python XML模块
2021-05-14 00:27
                         标签:test   pytho   imp   ext   遍历   文件   parse   child   python    python XML模块 标签:test   pytho   imp   ext   遍历   文件   parse   child   python    原文地址:https://www.cnblogs.com/anhao-world/p/13127294.htmlimport xml.etree.ElementTree as ET
tree = ET.parse("xmltest.xml")#操作的文件
root = tree.getroot()#获取一个内存地址
print(root.tag)#标签名
# 遍历xml文档
for child in root:
    print(child.tag, child.attrib)
    for i in child:
        print(i.tag, i.text,i.attrib)#获取头,内容,属性
# 只遍历year 节点
for node in root.iter(‘year‘):
    print(node.tag, node.text)
下一篇:Java异常