[Tutor] Parsing XML with minidom? (original) (raw)
Ertl, John John.Ertl at fnmoc.navy.mil
Thu Jul 8 19:41:50 CEST 2004
- Previous message: [Tutor] ebooks for python?
- Next message: [Tutor] Passing objects - okay now I get it.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 intlistif 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
- Previous message: [Tutor] ebooks for python?
- Next message: [Tutor] Passing objects - okay now I get it.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]