<% ' This is a simple demo file to illustrate the steps to access ' the talkingphonebook.com XML service and display the results ' via ASP. ' ' NOTE: As this is a demo file, exception handling and alternate flows ' were not a primary concern. The below code is not very robust ' and can easily present a 500 error if a particular situation arises ' (e.g. If an area is entered that we don't have listings for the below ' code will fail because the first call for the number of results will ' be null since it is not contained in the XML returned from the service. ' This null value isn't allowed when trying to use it to assign the ' numResult variable). ' ' ' Created September 2007 ' David Avery - davery@talkingphonebook.com Dim searchtype, area, keywords searchtype= Trim(Request("searchtype")) area= Trim(Request("area")) keywords= Trim(Request("keywords")) If searchtype = "" Then %>
Business Search
Find:
Where:


<% Else toResolve = 10000 toConnect = 10000 toSend = 10000 toReceive = 10000 Dim currNode Dim numResults Set srvXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0") URL= "http://www.talkingphonebook.com/wdpsearch/businessdataaccessxml.htm?searchtype=" + searchtype + "&keywords=" + keywords + "&area=" + area srvXmlHttp.open "GET", URL, false srvXmlHttp.setTimeouts toResolve, toConnect, toSend, toReceive ' not needed but a handy feature srvXmlHttp.send() if srvXmlHttp.status = 200 Then ' not needed but also a handy feature result = srvXmlHttp.responseText Dim xml Set xml = Server.CreateObject("MSXML2.DOMDocument.4.0") If xml.load(srvXmlHttp.responseStream) Then xml.setProperty "SelectionLanguage", "XPath" Set currNode = xml.selectSingleNode("//metadata/numresults") numResults = currNode.Text %> There were <%=numResults%> listings found for <%=keywords%> in <%=area%>

<% Set objListings = xml.selectNodes("//listings/listing") For i=0 To 9 Set objListing = objListings.item(i) Set objTitle = objListing.selectSingleNode("title") title = objTitle.Text Set objAddress = objListing.selectSingleNode("line/address") address = objAddress.Text Set objCity = objListing.selectSingleNode("line/city") city = objCity.Text Set objState = objListing.selectSingleNode("line/state") state = objState.Text Set objZip = objListing.selectSingleNode("line/zip") zip = objZip.Text Set objPhone = objListing.selectSingleNode("line/phone") phone = objPhone.Text %> <% Next %>
<%=title%>
<%=address%>
<%=city%>,<%=state%> <%=zip%>
Phone: <%=phone%>
<% Else ' Handle failure Response.Write("load failed") End If end if %> <% End If %>