The ASP page makes queries against a DOM object loaded from the contacts.xml file. For example, if the request comes with the a query string "SearchID=John Doe", the ASP page returns the contact information for John Doe. Otherwise, it returns the contact information of all listed persons. If the specified person is not a listed entry, the ASP returns an error to the client.
ASP page (contact.asp)
<%@language="javascript"%>
<%
var xpath;
var sName=Request.QueryString("SearchID")();
if (sName)
xpath = "//contact[name='" + sName + "']";
else
xpath = "contacts";
try {
var oDs = Server.CreateObject("MSXML2.DOMDocument.5.0");
oDs.async = false;
oDs.resolveExternals = false;
oDs.validateOnParse = false;
var path = Server.MapPath("contacts.xml");
if ( oDs.load(path) == true ) {
var oContact= oDs.selectSingleNode(xpath);
Response.ContentType = "text/xml";
Response.Write(oContact.xml);
}
}
catch (e) {
Response.ContentType = "text/xml";
Response.Write("<error>failed to create Contacts:"
+"<desc>"+e.description+"</desc>"
+"</error>");
}
%>
To add the contact.asp file to the virtual directory
Now, build and run the XMLOverHTTP project. The result should be the output shown in the following topic.