test.xml
<A> <AA> <AAA name="aaa">AaA</AAA> <BBB></BBB> </AA> <BB> <CCC name="ccc">CcC</CCC> <DDD></DDD> </BB> </A>
1.读取信息
import xml.etree.ElementTree as ET tree = ET.parse("test.xml") print(tree.getroot()) print(tree.getroot().find("AA")) print(tree.getroot().find("BB/CCC").text) print(tree.getroot().find("BB/CCC").get("name"))
输出:
<Element 'A' at 0x000002719542A0E0> <Element 'AA' at 0x00000271956C4950> CcC ccc
标签:xml,文件,getroot,BB,python,tree,print,find From: https://www.cnblogs.com/hardfood/p/17031249.html