David542
David542

Reputation: 110492

Find root node name using lxml

Given the following:

>>> from lxml import etree
>>> contents=open('file.xml').read()
>>> node=etree.fromstring(contents)

How would I get the root tag name of the node? For example, if the xml were:

<Orders>
 <Order>
  <Digital_Order>1021</Digital_Order>
 </Order>
</Orders>

It would return "Orders".

Upvotes: 3

Views: 2286

Answers (2)

Wolph
Wolph

Reputation: 80111

node is your root node actually.

But you might be experiencing problems because of the invalid xml, the last orders should be </Orders>

Upvotes: 0

Colin Dunklau
Colin Dunklau

Reputation: 3111

Should just be the simple node.tag

Upvotes: 5

Related Questions