[python xml 学习篇][0]

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

posted @ 2017-06-16 15:31  liuzhipenglove  阅读(162)  评论(0编辑  收藏  举报