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
_______________________________________________
XML-SIG maillist  -  XML-SIG@python.org
http://mail.python.org/mailman/listinfo/xml-sig

Reply via email to