首页 > 编程语言 > 详细

[python xml 学习篇][0]

时间:2017-06-16 15:59:18      阅读:258      评论:0      收藏: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

[python xml 学习篇][0]

原文:http://www.cnblogs.com/liuzhipenglove/p/7027783.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!