【发布时间】:2015-03-03 02:09:36
【问题描述】:
我有一个 xml 文件,在它的中间我有一个这样的块:
...
<node id = "1" >
<ngh id = "2" > 100 </ngh>
<ngh id = "3"> 300 </ngh>
</node>
<node id = "2">
<ngh id = "1" > 400 </ngh>
<ngh id = "3"> 500 </ngh>
</node>
...
并试图得到
1, 2, 100
1, 3, 300
2, 1, 400
2, 3, 500
...
我发现了一个类似的问题并做了以下
from xml.dom import minidom
xmldoc = minidom.parse('file.xml')
nodelist = xmldoc.getElementsByTagName('node')
for s in nodelist:
print s.attributes['id'].value)
有没有办法让我获得标签之间的值(即 100、300、400)?
【问题讨论】:
标签: python xml xml-parsing minidom