[Tutor] Parsing XML with minidom (original) (raw)

[Tutor] Parsing XML with minidom - problem solved

Ertl, John John.Ertl at fnmoc.navy.mil
Thu Jul 8 21:07:08 CEST 2004


I guess to get to the data I need to look at the childNode of each.

each.childNodes[0].data

John I am trying to use minidom to parse a small XML string. This is the test before I move onto bigger and better parsing but I am not getting the results I expected.

I am trying to make a list of integers from the XML.

def parsexml(xmlstring): import xml.dom.minidom

doc = xml.dom.minidom.parseString(xmlstring)
print doc.toxml()
intlist = []
modlist = doc.getElementsByTagName("element")  
for each in modlist:
   intlist.append(each.data)

return intlist

if name == "main": xml = """SOAP-ENV:Body 1 2 3 4 5 6 7 8 9 10 """ intlist = parsexml(xml) print intlist

Output is :

SOAP-ENV:Body 1 2 3 4 5 6 7 8 9 10 Traceback (most recent call last): File "./MyHandler.py", line 81, in ? value = parsexml(xml) File "./MyHandler.py", line 15, in parsexml print each.data AttributeError: Element instance has no attribute 'data'

If I instead of try to get the data I just : for each in modlist: print each.toxml()

I get the following...This makes me think that I am indeed looking for data in the correct place?

1 2 3 4 5 6 7 8 9 10 []

Thanks

John Ertl



More information about the Tutor mailing list