2
<student id="1" student:name="robert">
<sectionA>
<class name="first"/>
</sectionA>
</student>
<student id="2" student:name="lucky">
<sectionB>
<class name="first"/>
</sectionB>
</student>
<student id="2" student:name="Dave">
<sectionA>
<class name="third"/>
</sectionA>
</student>
from xml.dom import minidom
dom1 = minidom.parse("file.xml")
student = dom1.getElementsByTagName("student")
for b in student:
sectionA = dom1.getElementsByTagName("sectionA")
for a in sectionA:
name = b.getAttribute("student:name")
print name
這給了我下面的輸出: 羅伯特 幸運 戴夫蟒蛇minidom命名XML解析器3
但是我期待下面的輸出 預期輸出: 羅伯特 戴夫
感謝 它的工作:) – wrdw