1

here is the xml sample

<?xml version="1.0" encoding="UTF-8"?>
  <BxfMessage id="urn:uuid:dd0a5a80-4217-a0df-a1f0-d62045e45f8a" dateTime="2017-08-04T09:00:00Z" xmlns="http://smpte-ra.org/schemas/2021/2008/BXF" xmlns:pmcp="http://www.atsc.org/XMLSchemas/pmcp/2007/3.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" messageType="Information" origin="Traffic System" originType="Traffic" userName="PlaylistScript" destination="Automation">
  <BxfData action="add">
  <Schedule action="add" type="Primary" scheduleId="urn:uuid:12234-1242-afef1-1341541" dayPattern="1000000" scheduleStart="2017-08-04T09:00:00Z" scheduleEnd="2017-08-05T09:00:00Z">
    <Channel channelNumber="1" status="active" type="digital_television" ca="false" shortName="LASER">
      <pmcp:Name lang="eng">LASER</pmcp:Name>
    </Channel>
    <ScheduleName>LASER_170804</ScheduleName>
    <!-- rev022 -->
     <ScheduledEvent>
       <ScheduleElements>
         <EventData eventType="Primary-ProgramHeader" action="add">
           <EventId>
             <EventId>urn:uuid:102F29C1-999F-4D6C-AF36-1235363AD</EventId>
           </EventId>
           <EventTitle>PAID PROGRAMMING</EventTitle>
           <PrimaryEvent>
             <ProgramEvent>
               <SegmentNumber>0</SegmentNumber>
               <ProgramName>PAID PROGRAMMING</ProgramName>
             </ProgramEvent>
           </PrimaryEvent>
           <StartDateTime>
             <SmpteDateTime broadcastDate="2017-08-04">
               <SmpteTimeCode>09:00:00:00</SmpteTimeCode>
              </SmpteDateTime>
           </StartDateTime>
           <LengthOption>
             <Duration>
               <SmpteDuration>
                 <SmpteTimeCode>00:30:00:00</SmpteTimeCode>
               </SmpteDuration>
             </Duration>
           </LengthOption>
           <EndMode>Duration</EndMode>
         </EventData>
       </ScheduleElements>
     </ScheduledEvent>
   </Schedule>
  </BxfData>
</BxfMessage>

Here is the Python code I'm using to try to strip the namespace from the element.tag string

    tree = etree.parse("file.xml")
    root = tree .getroot()
    objectify.deannotate(root, cleanup_namespaces=True, xsi=True, pytype=True)  # supposed to remove namespaces

    for element in root.iter():
        print("%s - %s" % (element.tag, element.text))

So I have this function that I need to remove the namespaces from this xml document I'm parsing. the deannotate function is still leaving them there when I traverse the xml tree. PyCharm Debugger

Example output would just be the element name and not the namespace prepended

So element would just be "BxfMessage", and not "http://smpte-ra.org/schemas/2021/2008/BXF BxfMessage"

I am on version 4.0 of lxml. I tried enabling all the options. I am not sure what I am doing wrong here.

cohortq
  • 677
  • 1
  • 5
  • 10
  • 1
    "namespaces that prepend the element name". What is that? Please show us complete code and XML so that we can reproduce the problem (a [mcve]). – mzjn Nov 08 '17 at 06:11
  • The `deannotate` function can be used to remove unused namespace declarations. It does not remove all namespaces. For a way to do that, see https://stackoverflow.com/a/30233635/407651. – mzjn Nov 08 '17 at 19:18
  • You may need to post desired output. It is unclear what you are trying to do. – Parfait Nov 08 '17 at 19:46
  • Is the goal to produce a new document that does not use namespaces at all? – mzjn Nov 09 '17 at 10:16
  • I just ended up getting all the values from the element.nsmap dict and stripped all the names I found from all the elements. I just thought that deannotate would do that for me. – cohortq Nov 15 '17 at 23:45

0 Answers0