简体   繁体   中英

Getting at a XML nodes with Minidom

I'm trying to parse an XML file with the following structure using minidom:

<?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. Can someone point me in the right direction?

Ok, so I was missing firstChild:

print name[0].firstChild.nodeValue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM