Posting Templates Directly to the Virtual Directory

XML and Internet Support

XML and Internet Support

Posting Templates Directly to the Virtual Directory

This Microsoft® Visual Basic® example shows how templates can be sent directly to the virtual directory without using a Web browser. In this example, a template consisting of a SELECT statement is sent directly to the nwind virtual directory. For information about how to create the nwind virtual directory, see Creating the nwind Virtual Directory.

  Dim xmlHttp As New MSXML2.xmlHttp
  Dim doc As New MSXML2.DOMDocument
  Dim strQuery As String
  Dim strURL As String
  Dim strPostBody As String

   ' Set the post body - this is the query/request.
  strPostBody = "<?xml version='1.0' encoding='UTF-16'?>                   " & _
                "<root>                                                    " & _
                "<sql:query xmlns:sql='urn:schemas-microsoft-com:xml-sql'> " & _
                " select OrderID, shipName from Orders for xml raw                                   " & _
                "</sql:query>                                              " & _
                "</root>                                                   "

   ' Validate the document using the MSXML parser. 
  doc.loadXML strPostBody
  
  If doc.parseError.errorCode Then
' Do something with the error.
  End If
  
   ' Post the template.
  xmlHttp.Open "POST", "http://localhost/nwind", False
  xmlHttp.setRequestHeader "Content-type", "application/xml"
  xmlHttp.send doc

   ' Retrieve the results.
   Debug.Print xmlHttp.responseText

See Also

Using IIS Virtual Directory Management for SQL Server Utility

Accessing SQL Server Using HTTP

Retrieving XML Documents Using FOR XML

Using XPath Queries