我试图找到一种在使用 minidom 解析 xml 文件时获取索引号的方法。xml 看起来像这样
<stuff>
<morestuff>
<sometag>catagory1</sometag>
<path pathversion="1">/path Im looking to for</path> #<--info i'm after
<path pathversion="2">/path I don't need</path>
<path pathversion="3">/path I don't need</path>
</morestuff>
<morestuff>
<sometag>catagory2</sometag>
<path pathversion="1">/other path I'm looking for</path> #<--info i'm after
<path pathversion="2">/path I don't need</path>
<path pathversion="3">/path I don't need</path>
</morestuff>
</stuff>
我想做这样的事情
for element in node.getElementsByTagName('sometag'):
if element.firstChild.data == 'catagory1':
elementid = element.indexnumber #<----how do I write the [0], or [1] to a variable so I can use it to discribe the position in the next line
var1 = node.getElementsByTagName('path')[elementid].firstChild.data
if element.firstChild.data == 'catagory2':
elementid = element.indexnumber
var2 = node.getElementsByTagName('path')[elementid].firstChild.data