[XML-SIG] parsing XML with minidom

kimmyaf flahertyk1 at hotmail.com
Wed Apr 28 23:37:13 CEST 2010


Thanks all for the help. This gives me alot of good options and I have a few
working.... I learned a lot!





kimmyaf wrote:
> 
> Hello. I've only done a litte bit of parsing with minidom before but I'm
> having trouble getting my values out of this xml. I need the latitude and
> longitude values in bold. I've tried several things. I think that I am
> getting into the location tag but maybe the getAttribute function is not
> correct for this example?
> 
> 
> 
> <GeocodeResponse>
>  <status>OK</status>
>  <result>
>   <type>street_address</type>
>   <formatted_address>50 Oakland St, Wellesley, MA 02481,
> USA</formatted_address>
>   <address_component>
>    <long_name>50</long_name>
>    <short_name>50</short_name>
>    <type>street_number</type>
>   </address_component>
>   <address_component>
>    <long_name>Oakland St</long_name>
>    <short_name>Oakland St</short_name>
>    <type>route</type>
>   </address_component>
>   <address_component>
>    <long_name>Wellesley</long_name>
>    <short_name>Wellesley</short_name>
>    <type>locality</type>
>    <type>political</type>
>   </address_component>
>   <address_component>
>    <long_name>Wellesley</long_name>
>    <short_name>Wellesley</short_name>
>    <type>administrative_area_level_3</type>
>    <type>political</type>
>   </address_component>
>   <address_component>
>    <long_name>Norfolk</long_name>
>    <short_name>Norfolk</short_name>
>    <type>administrative_area_level_2</type>
>    <type>political</type>
>   </address_component>
>   <address_component>
>    <long_name>Massachusetts</long_name>
>    <short_name>MA</short_name>
>    <type>administrative_area_level_1</type>
>    <type>political</type>
>   </address_component>
>   <address_component>
>    <long_name>United States</long_name>
>    <short_name>US</short_name>
>    <type>country</type>
>    <type>political</type>
>   </address_component>
>   <address_component>
>    <long_name>02481</long_name>
>    <short_name>02481</short_name>
>    <type>postal_code</type>
>   </address_component>
>   <geometry>
>    <location>
>     <lat>42.3118520</lat>
>     <lng>-71.2632680</lng>
>    </location>
>    <location_type>ROOFTOP</location_type>
>    <viewport>
>     <southwest>
>      <lat>42.3093524</lat>
>      <lng>-71.2665476</lng>
>     </southwest>
>     <northeast>
>      <lat>42.3156476</lat>
>      <lng>-71.2602524</lng>
>     </northeast>
>    </viewport>
>   </geometry>
>  </result>
> </GeocodeResponse>
> 
> 
> Code:
> 
> body = dom.getElementsByTagName('GeocodeResponse')[0]
> 
> for item in body.getElementsByTagName('location'):
>      lat = item.getAttribute('lat')
>      lng = item.getAttribute('lng')
> 

-- 
View this message in context: http://old.nabble.com/parsing-XML-with-minidom-tp28359328p28394291.html
Sent from the Python - xml-sig mailing list archive at Nabble.com.



More information about the XML-SIG mailing list