Reputation: 687
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.
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.
Upvotes: 1
Views: 1506