Adrocks__ Adrocks__ - 1 year ago 96
Python Question

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.

<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:

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.

kfb kfb
Answer Source

According to the minidom docs, it looks like .childNodes might be the thing you're looking for.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download