How to read root XML tag in python

丶灬走出姿态 提交于 2019-12-06 03:54:14

root is an instance of the Element class. Any such object will have a tag attribute. Just use root.tag. Given what you say in your question, this should produce the string "root".

You should be able to use the tag function to get the name of the node.

from xml.etree import ElementTree as ET
path = 'C:\cool.xml'
et = ET.parse ( path )
root = et.getroot()

if root.tag == "root":
  print "I'm the root"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!