How To Remove Root Element From Xml File Using Python?
I have my xml file like this : Gambardella, Matthew XML Developer's Gu
Solution 1:
In your case is enough to use list to get first element:
>>> s="""<root>
<catalog>
<book id="bk101">
...
""">>> import xml.etree.ElementTree as ET
>>> catalog = list( ET.fromstring(s) )[0] #<--- here>>> ET.tostring(catalog, encoding='utf8', method='xml')
Or use the iterator:
>>>catalog = next( ET.fromstring(s).iter() ) #<--- here
Post a Comment for "How To Remove Root Element From Xml File Using Python?"