toddpotter
asked on
Extract data from xml in vb.net
I am new to working with XML and need some help understanding how to cycle through an XML file and extract the data that I need in visual studio . net. Below is XML containing geocode data that I need to extract. In this case I need to extract the latitude an longitude tags <lat>33.7713652</lat> <lng>-84.3719365</lng> into variables Lat and Lng.
Thanks in advance for your help.
Here is the xml data:
<?xml version="1.0" encoding="UTF-8"?>
-<GeocodeResponse> <status>OK</status> -<result> <type>street_address</type > <formatted_address>460 North Avenue Northeast, Atlanta, GA 30308, USA</formatted_address> -<address_component> <long_name>460</long_name> <short_name>460</short_nam e> <type>street_number</type> </address_component> -<address_component> <long_name>North Avenue Northeast</long_name> <short_name>North Avenue NE</short_name> <type>route</type> </address_component> -<address_component> <long_name>Old Fourth Ward</long_name> <short_name>Old Fourth Ward</short_name> <type>neighborhood</type> <type>political</type> </address_component> -<address_component> <long_name>Atlanta</long_n ame> <short_name>Atlanta</short _name> <type>locality</type> <type>political</type> </address_component> -<address_component> <long_name>Atlanta</long_n ame> <short_name>Atlanta</short _name> <type>administrative_area_ level_3</t ype> <type>political</type> </address_component> -<address_component> <long_name>Fulton</long_na me> <short_name>Fulton</short_ name> <type>administrative_area_ level_2</t ype> <type>political</type> </address_component> -<address_component> <long_name>Georgia</long_n ame> <short_name>GA</short_name > <type>administrative_area_ level_1</t ype> <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>30308</long_nam e> <short_name>30308</short_n ame> <type>postal_code</type> </address_component> -<geometry> -<location> <lat>33.7713652</lat> <lng>-84.3719365</lng> </location> <location_type>ROOFTOP</lo cation_typ e> -<viewport> -<southwest> <lat>33.7700162</lat> <lng>-84.3732855</lng> </southwest> -<northeast> <lat>33.7727142</lat> <lng>-84.3705875</lng> </northeast> </viewport> </geometry> </result> -<result> <type>street_address</type > <formatted_address>460 North Road, Douglas, NE 68344, USA</formatted_address> -<address_component> <long_name>460</long_name> <short_name>460</short_nam e> <type>street_number</type> </address_component> -<address_component> <long_name>North Road</long_name> <short_name>N Rd</short_name> <type>route</type> </address_component> -<address_component> <long_name>Douglas</long_n ame> <short_name>Douglas</short _name> <type>locality</type> <type>political</type> </address_component> -<address_component> <long_name>Hendricks</long _name> <short_name>Hendricks</sho rt_name> <type>administrative_area_ level_3</t ype> <type>political</type> </address_component> -<address_component> <long_name>Otoe</long_name > <short_name>Otoe</short_na me> <type>administrative_area_ level_2</t ype> <type>political</type> </address_component> -<address_component> <long_name>Nebraska</long_ name> <short_name>NE</short_name > <type>administrative_area_ level_1</t ype> <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>68344</long_nam e> <short_name>68344</short_n ame> <type>postal_code</type> </address_component> -<geometry> -<location> <lat>40.5918115</lat> <lng>-96.4191915</lng> </location> <location_type>RANGE_INTER POLATED</l ocation_ty pe> -<viewport> -<southwest> <lat>40.5904695</lat> <lng>-96.4205405</lng> </southwest> -<northeast> <lat>40.5931675</lat> <lng>-96.4178426</lng> </northeast> </viewport> -<bounds> -<southwest> <lat>40.5918115</lat> <lng>-96.4191916</lng> </southwest> -<northeast> <lat>40.5918255</lat> <lng>-96.4191915</lng> </northeast> </bounds> </geometry> <partial_match>true</parti al_match> </result>
Thanks in advance for your help.
Here is the xml data:
<?xml version="1.0" encoding="UTF-8"?>
-<GeocodeResponse> <status>OK</status> -<result> <type>street_address</type
I see multiple <lat> and <lng> nodes in that sample. So which ones do you need?
ASKER
Multiple get returned so I would go with the 1st occurance.
OK, but there are multiple parents. Do you need the long/lat that is within the <location> node, the <southeast> node, the <southwest> node, etc., etc.
ASKER
Sorry. For now, the long/lat within the <location> would be sufficient.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.