Parsing XML

Parsing XML

am 08.02.2006 00:14:04 von gebelo

I'm messing around with a mapping application using the Yahoo online
geocoder.

In my application, the user enters an address search in a form and the
results page loops through the recordset of matching results.

What I want to do is take the address for each matching result and send
it on to the Yahoo geocoder and suck in the latitude and longitude.

So inside my loop, I have this:

<%
url =
"http://api.local.yahoo.com/MapsService/V1/geocode?appid=myy ahooid&street="&rs("location")&chr(38)&"city="&rs("townname" )&chr(38)&"state=NJ"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
straddress=xmlhttp.responseText
response.write straddress&"
"
set xmlhttp = nothing
%>

This code creates a variable straddress for each record that contains
this chunk of XML:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps
http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xs d"> precision="address">40.887163-74.002151

100
MINELL
PL
TEANECKNJ07666-5510US


What's the easiest way to examine that chunk and pull out

strlatitude = 40.887163
strlongitude = -74.002151

TIA...

Re: Parsing XML

am 08.02.2006 09:56:40 von Anthony Jones

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
elemRes = xmlhttp.responseXML.documentElement
stratitude = elemRes.selectSingleNode("Latitude").Text
strlongtitude = elemRes.selectSingleNode("Longitude").Text

Anthony.

Re: Parsing XML

am 08.02.2006 12:40:03 von reb01501

gebelo@gmail.com wrote:
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps
> http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xs d"> > precision="address">40.887163-74.002151

100
> MINELL
> PL
TEANECKNJ07666-5510US
>
>
> What's the easiest way to examine that chunk and pull out
>
> strlatitude = 40.887163
> strlongitude = -74.002151
>
> TIA...
Anthony Jones wrote:
> set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
> xmlhttp.open "GET", url, false
> xmlhttp.send ""
> elemRes = xmlhttp.responseXML.documentElement
> stratitude = elemRes.selectSingleNode("Latitude").Text
> strlongtitude = elemRes.selectSingleNode("Longitude").Text
>
> Anthony.
This is perfectly correct. I just want to add that you should add some
error-handling to this, otherwise you could subject your users to cryptic
messages about "something" not being an object.
My preference is to do something like this:

dim elemRes, latNode, longNode
set elemRes = xmlhttp.responseXML.documentElement
set latNode=Nothing
set latNode=elemRes.selectSingleNode("Latitude")
if latNode is Nothing then
'handle situation where call to url returned no latitude
else
stratitude = latNode.nodeValue
end if

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"