[XML-SIG] parsing XML with minidom
Stefan Behnel
stefan_ml at behnel.de
Wed Apr 28 07:43:32 CEST 2010
kimmyaf, 27.04.2010 23:32:
>> handler = urllib2.urlopen(url)
>> xml_response = handler.read()
>> handler.close()
>>
>> tree = ET.parse("GeocodeResponse.xml")
>> Do I have to use a file? I tried to do
>>
>> tree = ET.parse(xml_response)
parse() is meant for parsing files. Use fromstring() to parse from a string.
This works for me:
>>> import xml.etree.cElementTree as ET
>>> tree = ET.parse('gmap.xml')
>>> print [ (el.findtext('lat'), el.findtext('lng'))
... for el in tree.getiterator('location') ]
[('42.3118520', '-71.2632680')]
Stefan
More information about the XML-SIG
mailing list