Help updating asp/vbscript to parse XML webservice results

The webservice I was using to get address and geo-code data has changed their XML results format and label/node names.
I can’t seem to get the this code to properly parse/read the new nodes (likley because I don’t know how to properly identify the node name/child.node name).

Any help would be greatly appreciated.

Notes:
The function that calls the webservice is named GeoCodeFunction
The IF/THEN to check for ‘precision’ needs to be changed to a more simple check for ‘quality’ > 85
The ZipCode variable needs to now = XML reslut: ‘uzip’
The ZipCodePlusFour variable needs to now = XML result: ‘postal’
You’ll see a funtion named GetRecordSet in the code - it query’s the DB

I would be DELIGHTED to pay someone to help me with this…
but I’m also happy to try to learn from you folks how to properly read XML node results into variables, and do it here so that others can follow and learn from my ignorance.

Thanks.

  • Michael

This asp page (below) is called after an HTML form submission
which writes user data to the DB and:

a) opens a DB connection, checks a website visitor’s login status, gets their userID
b) retreives user’s data (address) from a MySQL DB table, name: ‘users’
c) if exists, sends the address data to a webservice (external function: ‘geocode’)
d) reads the returned XML results
e) updates the database table with the new address data
f) redirects the user to another html/asp page


<!–#include file=“./include/functions.asp”–>

&lt;%
call openDB
call checkLogin
if not session("userType") = "P" then response.redirect "sitter_main.asp"
idUser=session("idUser")

set oUser=getRecordSet("SELECT * FROM Users WHERE idUser=" & idUser)

if not isnull(oUser("zipCode")) and not isEmpty(oUser("zipCode")) then
 on error resume next
 parsedXML=GeoCode(oUser("streetAddress"), oUser("city"), oUser("state"), oUser("zipCode"))
 on error goto 0

	if err.number=0 and Len(ParseTag("Latitude",parsedXML)) &gt; 0 then
		if instr(1,parsedXML,"precision=""address""") &gt; 1 or instr(1,parsedXML,"precision=""street""") &gt; 1 then
			ExecuteSQL "Update Users SET " & _
				"streetaddress=""" & ParseTag("Address",parsedXML) & """," & _
				"city=""" & ParseTag("City",parsedXML) & """," & _
				"zipCode=""" & Left(ParseTag("Zip",parsedXML),5) & """," & _
				"zipCodePlusFour=""" & ParseTag("Zip",parsedXML) & """," & _
				"Latitude=" & ParseTag("Latitude",parsedXML) & "," & _
				"Longitude=" & ParseTag("Longitude",parsedXML) & "," & _
				"`status`=""A""," & _
				"Comments="""" " & _
				"WHERE idUser=" & idUser 'active'
		elseif instr(1,parsedXML,"precision=""zip""") &gt; 1 then
			ExecuteSQL "Update Users SET " & _
				"zipCode=""" & Left(ParseTag("Zip",parsedXML),5) & """," & _
				"zipCodePlusFour=""" & ParseTag("Zip",parsedXML) & """," & _
				"Latitude=" & ParseTag("Latitude",parsedXML) & "," & _
				"Longitude=" & ParseTag("Longitude",parsedXML) & "," & _
				"Comments=""""," & _
				"`status`=""E"" WHERE idUser=" & idUser 'active'
		end if
	else
		if Len(ParseTag("Zip",parsedXML)) = 0 then
			ExecuteSQL "Update Users SET " & _
				"`Comments`=""" & ParseTag("Message",parsedXML) & "&lt;br&gt;" & validSQL(parsedXML,"S") & """," & _
				"`status`=""E"",Latitude=NULL,Longitude=NULL WHERE idUser=" & idUser
		else
			ExecuteSQL "Update Users SET " & _
				"streetaddress=""" & ParseTag("Address",parsedXML) & """," & _
				"city=""" & ParseTag("City",parsedXML) & """," & _
				"zipCode=""" & Left(ParseTag("Zip",parsedXML),5) & """," & _
				"zipCodePlusFour=""" & ParseTag("Zip",parsedXML) & """," & _
				"`status`=""E"",Latitude=NULL,Longitude=NULL WHERE idUser=" & idUser
		end if
	end if
end if

response.write "&lt;p /&gt;"
response.write parsedXML
response.redirect "parent_main.asp"
call closeDB
%&gt;

These are the new webservice XML results and node names:

<?xml version="1.0" encoding="UTF-8" ?>
  • 0 No error 87 (replacement for 'precision - different values!)
  • 87 (was 'precision' - different values!) 41.362040 (was 'Latitude') -81.359281 (was 'Longitude') 1234 Any St (was 'Address') 44123-1234 (was 'Zip') Any Town (was 'City') 44123 (was 'Zip' - truncated, left, 5)

And here is the external function that submits to the webservice:

Function GeoCode(street, city, state, zipcode)

    set objDocXML = Server.CreateObject("MSXML2.DomDocument")
    set objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")
    set objDocXML = Server.CreateObject("MSXML2.DOMDocument")
    Dim XMLresponse,i
    Dim webXML
    Dim webService

    Dim ITSArray,ITSReturn

    webService = "http://where.yahooapis.com/geocode?&appid=[appid]?&location="&street="+street+"&city="+city+"&state="+state+"&zip="+zipcode"

    objXMLHTTP.Open "post", webService, False

    objXMLHTTP.send payload
    XMLresponse = objXMLHTTP.responseText

    objDocXML.loadXML (XMLresponse)

	GeoCode=objDocXML.xml


End Function

Correct Mapping of new XML nodes to Database Fields:

XML RESULT Database Field

<quality> (does not exist)
<line1> streetAddress
<city> city
<statecode> state
<uzip> zipCode
<postal> zipCodePlusFour
<latitude> Latitude
<longitude> Longitude
<ErrorMessage> comments


Detailed information on the webservice can be found here:
http://developer.yahoo.com/geo/placefinder/