ASP Page: contact.asp (XMLOverHTTP Example)

 

The ASP page makes queries against a DOM object loaded from the contacts.xml file. For example, if the request comes with the 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 oDOMDoc = Server.CreateObject("MSXML2.DOMDocument.6.0");

    oDOMDoc.async = false;
    oDOMDoc.resolveExternals = false;
    oDOMDoc.validateOnParse = false;

    var path = Server.MapPath("contacts.xml"); 
    if ( oDOMDoc.load(path) == true ) {
      var oContact= oDOMDoc.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, Set Up My Visual C++ Project the Source: XMLOverHTTP.cpp. The result should be the Output from XMLOverHTTP Example shown in the following topic.

See Also

Make XML Requests Over HTTP (Smart)