Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Developer's Guide

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

  1. 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
  2. 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.