Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling xml errors

Status
Not open for further replies.

gwrman

IS-IT--Management
Dec 20, 2005
94
CA
I use the following code with the yahoo search api:

Code:
<%@ Language=VBScript %>
<%


Dim mysearch, mypage, pageinc, xml, objNodeList, objNode, objNode2

mysearch=Left(Request.QueryString("q"),256)
mypage = Request.QueryString("p")
if mypage=0 then mypage = 1

%>
<html>
<head>
<title>Yahoo! Web Search API In ASP</title>
</head>
<body>
<form method="GET" action="websearch.asp">
<b>Yahoo! Web Search:</b><br>
<input type="text" name="q" maxlength=256 size=40 value='<%=mysearch%>' size=15><input type="submit" value="Search!"></form><br>
<% if mysearch<>"" then

Dim Url
Url = "[URL unfurl="true"]http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=someappid&query="[/URL] & Server.URLEncode(mysearch) & "&results=50&start=" & mypage

Set XML = Server.CreateObject("msxml2.DOMDocument.3.0")
XML.async = false
XML.setProperty "ServerHTTPRequest", True
XML.validateOnParse = false
XML.preserveWhiteSpace = false

If Not XML.Load(Url) Then

Response.write "<P>ERROR<br>code: " & _
XML.parseError.errorCode & _
"<br>Linea/Col: " & _
XML.parseError.line & "/" & _
XML.parseError.linepos & "</P><br /><p>" & _
XML.parseError.srcText & "</P>"
Else

Dim rTitle, rSummary, rUrl, rClickUrl, rMimeType, rModDate, rCache

pageinc=1

Set objNodeList = XML.getElementsByTagName("Result")
For Each objNode In objNodeList
For Each objNode2 In objNode.childNodes

Select Case objNode2.nodeName
	Case "Title"
		rTitle = objNode2.text
	Case "Summary"
		rSummary = objNode2.text
	Case "Url"
		rUrl = objNode2.text
	Case "ClickUrl"
		rClickUrl = objNode2.text
	Case "MimeType"
		rMimeType = objNode2.text
	Case "ModificationDate"
		rModDate = objNode2.text
	Case "Cache"
		rCache = objNode2.text
	End Select
Next

	' rURL can contain more than one URL seperated by spaces
	if InStr(rURL," ")>0 then rURL = Left(rURL,InStr(rURL," ")-1)
	response.write("<table border=0><tr><td><a href='" & rClickUrl & "'>" & rTitle & "</a><br>" & rSummary & "<br><font color='gray'>Date: " & DateAdd("s", rModDate, "01/01/1970 00:00:00") & " | <a style='color: gray;' href='" & rCache & "'>Cache</a> | MimeType: " & rMimeType & "</font></td></tr></table><br>")
	rTitle=""
	rSummary=""
	rUrl=""
	rClickUrl=""
	rMimeType=""
	rModDate=""
	rCache=""

    pageinc=pageinc+1
Next

set objNodeList = Nothing

end if

set xml = nothing


  if mypage>1 then
	response.write("<a href=?q=" & Server.URLEncode(mysearch) & "&p=" & cstr(mypage-50))
	response.write("><b><<< Previous Page</b></a> | ")
  end if


  if pageinc=>16 then
	response.write("<a href=?q=" & Server.URLEncode(mysearch) & "&p=" & cstr(mypage+50))
	response.write("><b>Next Page >>></b></a>")
  end if
%>
<br>powered by Yahoo! Search
<% end if %>
</body>
</html>

I am getting an error, presumable because of an ampersand with whitespace that is in one of the results, see specific error below: (notice the ampersand in title?_)

ERROR
code: -1072896749
Linea/Col: 51/99
txt: How to download CBC's technology show Quirks & Quarks to your iPod.
so, how can I handle this? (i dont really even need the title - but if i did, is there a way to ahndle it? is there a way not to return the title at all?
 
thanks, i'll look in to that.

How could this be implemented to prevent the xml error im wondering? Any pointers?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top