参考:https://www.jb51.net/article/63780.htm
tree = ET.parse(“country.xml”)
import xml.etree.ElementTree as ET
tree = ET.parse("country.xml")
root = tree.getroot()
root.tag
for child in root:
print child.tag, "---", child.attrib
或者:
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
tree = ET.parse("country.xml") # <class 'xml.etree.ElementTree.ElementTree'>
root = tree.getroot() # 获取根节点 <Element 'data' at 0x02BF6A80>