Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find root node name using lxml

Tags:

python

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".

like image 267
David542 Avatar asked Nov 29 '25 08:11

David542


1 Answers

Should just be the simple node.tag

like image 65
Colin Dunklau Avatar answered Nov 30 '25 21:11

Colin Dunklau