[XML-SIG] parsing XML with minidom
flahertyk1 at hotmail.com
Tue Apr 27 23:32:39 CEST 2010
Now that I look at my file it does not look well formed. Do I have to use a
file? I tried to do
tree = ET.parse(xml_response)
but i got a file IO error...
> I don't really know... Here's the whole story.
> I am retrieving the xml by calling this link.
> Here's the entire function:
> addr = '50+Oakland+St,Wellesley,MA,02481'
> def geocode_addr(addr):
> hostname = 'http://maps.google.com/maps/api/geocode/xml?'
> prefix = 'address='
> sensor = '&sensor=true'
> url = hostname + prefix + addr + sensor
> print url
> handler = urllib2.urlopen(url)
> xml_response = handler.read()
> print xml_response
> #dom = minidom.parseString(xml_response)
> tree = ET.parse("GeocodeResponse.xml")
> print 'here'
> for tag in tree.getiterator("location"):
> print 'here1'
> print tag.findtext("lat")
> *** I actually just pasted the xml from the shell where i printed
> xml_response and saved it into an xml file in my folder called
> GeocodeResponse.xml to test this... before going through the work of
> saving the xml into a file. I got the "here" but not the "here1"
> I'm attaching my actual file..
> Sorry! I appreciate the help! this is the last piece of functionality i
> need to get working for my programming assignment!
> Stefan Behnel-3 wrote:
>> kimmyaf, 26.04.2010 23:14:
>>> Stefan Behnel-3 wrote:
>>>> kimmyaf, 26.04.2010 00:24:
>>>>> Hello. I've only done a litte bit of parsing with minidom before but
>>>>> having trouble getting my values out of this xml. I need the latitude
>>>>> longitude values in bold.
>>>> I don't see anything 'bold' in your mail, but your example tells me
>>>> data you mean.
>>>> Here is some untested code using xml.etree.cElementTree:
>>>> import xml.etree.cElementTree as ET
>>>> tree = ET.parse("thefile.xml")
>>>> for tag in tree.getiterator("location"):
>>>> print tag.findtext("lat"), tag.findtext("lng")
>>> Thanks Stefan. I tried this but it's not getting into the for block for
>> Maybe the document uses namespace declarations that you forgot to show
>> XML-SIG maillist - XML-SIG at python.org
View this message in context: http://old.nabble.com/parsing-XML-with-minidom-tp28359328p28382343.html
Sent from the Python - xml-sig mailing list archive at Nabble.com.
More information about the XML-SIG