from xml.etree.ElementTree import parse f=open("web.xml") et=parse(f) root=et.getroot() print(root.tag) # print(root.attrib) # print(root.text) # print(list(root.iter()))#可以找到所有的节点# # print(root.find("param-value"))#只可以找到它自己这个子层级下面的元素 print(root.findall(".//listener-class"))#查找子节点叫这个名字的所有元素 print(root.findall("listener/*"))#选择子节点下的所有元素 print(root.findall(".//listener-class/.."))#选择某个节点的所有夫元素 print(root.findall(".//listener[@name]"))#选择某个节点包含某个属性的所有元素 print(root.findall(".//listener-class[@name]"))
python读取xml
最新推荐文章于 2024-05-03 22:13:07 发布