我正在尝试使用Untangle library解析XML文件。
我需要从XML文件中生成一个树(层次结构),如下所示:
root.countries.country[1].AnimalShop[1].Name = "DogShop"
root.countries.country[1].AnimalShop[2].Name = "CatShop"
root.countries.country[1].AnimalShop[3].Name = "CowShop"
root.countries.country[1].SeaShop[2].Name = "SharkShop"
root.countries.country[1].SeaShop[2].Address = "1 road of stockoverflow"
答案 0 :(得分:0)
import untangle
obj = untangle.parse("D:/.....xml")
#use "children" it's predeveloped
mainmodel = obj.GrandFather.children
for element in mainmodel:
model =element.children
for ele in model:
print(ele._name)