更新时间:2023-11-07 12:16:16
from lxml import etree as ET
xmlString = """
<some_root_name>
<tag_x>bubbles</tag_x>
<tag_y>car</tag_y>
<tag...>42</tag...>
</some_root_name> """
document = ET.fromstring(xmlString)
for elementtag in document.getiterator():
print "elementtag name:", elementtag.tag
编辑:
要从文件中读取而不是从字符串中读取
To read from file instead of from string
document = ET.parse("myxmlfile.xml")