我正在尝试使用以下内容解析 xml
<File version="5.6">
<Parent name="A">
<Child name="a"/>
<Child name="b"/>
</Parent>
<Parent name="B">
<Child name="c"/>
<Child name="d"/>
</Parent>
<Parent name="C">
<Child name="e"/>
<Child name="f"/>
</Parent>
</File>
我使用了以下代码
for child in tree.getroot().findall('./Parent/Child')
print child.attrib.get("name")
它只打印没有父母姓名的所有孩子的姓名。我可以这样打印每个孩子的相关父母姓名吗?
A has a b
B has c d
C has e f