Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
鉴于以下情况:
>>> from lxml import etree >>> contents=open('file.xml').read() >>> node=etree.fromstring(contents)
如何获取节点的根标签名称?例如,如果 xml 是:
<Orders> <Order> <Digital_Order>1021</Digital_Order> </Order> </Orders>
它会返回"Orders"。
"Orders"
应该只是简单的node.tag
node.tag
node实际上是你的根节点。
node
但是您可能会因为无效的 xml 而遇到问题,最后的订单应该是</Orders>
</Orders>