Blog
RSS feed

Using the Live Search API Version 2.0 Beta with ASP

This post demonstrates using the API with good old ASP - plus a little XPATH magic.

-- Alessandro

 

<%@ Language=VBScript %>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>Untitled Page</title>

</head>

<body>

<%query = request("query") %>

<%AppID = "your AppID here" %>

<form name="xmlForm" action="LSAPI2noXSL.asp" method="post">

<input type="text" name="query" value="<%= query %>"/>

<input type="submit" name="searchBtn" value="Search"/>

<%

If query<>"" Then

fullurl = "http://api.search.live.net/xml.aspx?sources=web&appid=" & AppID & "&query=" & query

Set webreq = Server.CreateObject("MSXML2.XMLHTTP.4.0")

webreq.Open "GET", fullurl, False 'synchronous request

webreq.send

If webreq.status = 200 Then

Response.Write "<ul>"

Set results = webreq.responseXML.selectNodes("//*[local-name(.)='WebResult']")

For Each result in results

Response.Write "<il><a href='"

Response.Write result.selectSingleNode("*[local-name(.)='Url']").text

Response.Write "'><h3>"

Response.Write result.selectSingleNode("*[local-name(.)='Title']").text

Response.Write "'</h3></a><p>"

Response.Write result.selectSingleNode("*[local-name(.)='Description']").text

Response.Write "</p></li>"

Next

Response.Write "</ul>"

End If

End If

%>

</form>

</body>

</html>

Published Friday, January 16, 2009 1:38 PM by ianwh