[英]Getting at a XML nodes with Minidom
I'm trying to parse an XML file with the following structure using minidom: 我正在尝试使用minidom解析具有以下结构的XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<Product>
<Product version='1'>
<Name>My Product</Name>
<Type>Physical</Type>
<Stock>2</Visibility>
</Product>
So far, I've got something like this: 到目前为止,我有这样的事情:
xmldoc = minidom.parse(file)
name = xmldoc.getElementsByTagName('Name')
print name[0].nodeValue
But this returns None. 但这返回None。 Can someone point me in the right direction?
有人可以指出我正确的方向吗?
Ok, so I was missing firstChild: 好吧,所以我很想念firstChild:
print name[0].firstChild.nodeValue 打印名称[0] .firstChild.nodeValue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.