首页 > 代码库 > 遍历XML文件

遍历XML文件

#encoding=utf-8from xml.etree import ElementTree as ET#要找出所有人的年龄per=ET.parse(‘d:\\1.xml‘)p=per.findall(‘./STATION‘)for x in p:    print x.attribprintfor oneper in p:  #找出person节点    for child in oneper.getchildren(): #找出person节点的子节点        print child.tag,‘:‘,child.text    print ‘############‘