[英]Python XML parse issues
Currently trying to parse some XML using python, so far I've managed to get the name of the tag however I can't figure out how to get the data from inside this. 当前正在尝试使用python解析一些XML,到目前为止,我已经设法获得了标签的名称,但是我不知道如何从其中获取数据。
<Fragment name="Located At">Sector 121212</Fragment>
The above is an example of the XML file, I can get the "Located At" part out but not the "Sector 165658" I am currently using the following: 上面是XML文件的示例,我可以获取“ Located At”部分,但不能获取“ Sector 165658”,我目前正在使用以下代码:
xmldoc = minidom.parse('file.xml')
itemlist = xmldoc.getElementsByTagName('Fragment')
for items in itemlist:
print (items.attributes['name'].value)
I can't for the life of me remember that the "name" for the section is I feel like this is going to be a simple answer and I'm going to look like an idiot but we shall see. 我一辈子都记不起,该节的“名称”是我觉得这将是一个简单的答案,我看起来像个白痴,但我们会看到的。
根据minidom
文档 ,看起来.childNodes
可能是您正在寻找的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.