Extracting Nested Namespace From A Xml Using Lxml
I'm new to Python and currently learning to parse XML. All seems to be going well until I hit a wall with nested namespaces. Below is an snippet of my xml ( with a beginning and c
Solution 1:
This program prints the namespace of the indicated tag:
from lxml import etree
xml = etree.XML('''<?xml version="1.0" encoding="UTF-8"?><CompositionPlaylistxmlns="http://www.digicine.com/PROTO-ASDCP-CPL-20040511#"><!-- Generated by orca_wrapping version 3.8.3-0 --><Id>urn:uuid:e0e43007-ca9b-4ed8-97b9-3ac9b272be7a</Id><cc-cpl:MainClosedCaptionxmlns:cc-cpl="http://www.digicine.com/PROTO-ASDCP-CC-CPL-20070926#"><Id>urn:uuid:0607e57f-edcc-46ec- 997a-d2fbc0c1ea3a</Id><EditRate>24 1</EditRate><IntrinsicDuration>2698</IntrinsicDuration></cc-cpl:MainClosedCaption></CompositionPlaylist>
''')
print etree.QName(xml.find('.//{*}MainClosedCaption')).namespace
Result:
http://www.digicine.com/PROTO-ASDCP-CC-CPL-20070926#
Reference: http://lxml.de/tutorial.html#namespaces
Post a Comment for "Extracting Nested Namespace From A Xml Using Lxml"