tree = ET.parse("Result.xml")
root = tree.getroot()
print type(root)
print root.tag # 得到root 标签
print root.text #得到标签的值
print root.attrib
def parserResultXml(xmlfile):
tree = ET.parse(xmlfile)
result = tree.getroot()[0][1]
for child in result:
if child.tag == "description":
pass
elif child.tag == "name":
pass
elif child.tag == "passIndex":
pass
elif child.tag == "benchmarkRunId":
pass
else:
print child.tag +":"+child.text
if __name__ == ‘__main__‘:
parserResultXml("Result.xml")
学习网址:
https://docs.python.org/2.7/library/xml.etree.elementtree.html#module-xml.etree.ElementTree
时间: 2024-12-08 08:05:33