ASP Page: contact.asp
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
- Create an empty text file in the directory you created to correspond to your virtual directory (for example, c:\XMLOverHTTP, corresponding localhost/sxh). Name the new file contact.asp
- Copy the resource listing above, and paste it into the XML file you just created. Save the file.
Now, build and run the XMLOverHTTP project. The result should be the output shown in the following topic.