Executing XPath Queries Using HTTP

XML and Internet Support

XML and Internet Support

Executing XPath Queries Using HTTP

The XPath queries against annotated XML-Data Reduced (XDR) schema can be specified directly in the URL. For more information about the URL syntax that is supported by the SQL ISAPI extension, see URL Access.

The annotated XDR schemas provide an XML view of the relational data. To execute an XPath query against an annotated XDR schema, the schema file is specified as part of the URL.

To specify an XPath query against an annotated XDR schema, you must create a virtual name of schema type using the IIS Virtual Directory Management for SQL Server utility. The XDR schema specified in the URL must be stored in the directory associated with virtual name of schema type or one of its subdirectories:

  • If the annotated XDR schema is stored in the directory associated with the virtual name of schema type, the URL query looks like:
    http://IISServer/nwind/SchemaVirtualName/XDRSchema.xml/XpathQuery
    
  • If the annotated XDR schema is stored in a subdirectory (xyz) associated with virtual name of schema type, the path relative to the directory associated with virtual name of schema type is included in the URL. In this case, the URL query looks like:
    http://IISServer/nwind/SchemaVirtualName/xyz/XDRSchema.xml/XpathQuery
    
Examples

In this example, nwind is a virtual directory created using the IIS Virtual Directory Management for SQL Server utility, and schema is the virtual name of schema type defined when the virtual directory is created (any name can be given to a virtual name when it is created).

A. Specify an XPath query in the URL

For example, consider this annotated XDR schema:

<?xml version="1.0" ?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
        xmlns:dt="urn:schemas-microsoft-com:datatypes"
        xmlns:sql="urn:schemas-microsoft-com:xml-sql">

  <ElementType name="Customer" sql:relation="Customers" >
    <AttributeType name="CustomerID" />
    <AttributeType name="ContactName" />
    <AttributeType name="Phone" />

    <attribute type="CustomerID" />
    <attribute type="ContactName" />
    <attribute type="Phone" />
  </ElementType>
</Schema>

For illustration purposes, this XDR schema is stored as MySchema.xml in the directory associated with the virtual name of schema type.

This URL executes an XPath query against the XDR schema (MySchema.xml) specified in the URL. The XPath query requests all the customers with CustomerID of ALFKI.

http://IISServer/nwind/schema/Schema2.xml/Customer[@CustomerID="ALFKI"]

This is the result:

<Customer CustomerID="ALFKI" ContactName="Maria Anders" Phone="030-0074321" /> 

If the query returns more than one customer, you must specify the root keyword to return a well-formed XML document. The following XPath query returns all the customers. In the URL, the root keyword is specified:

http://IISServer/nwind/schema/Schema2.xml/Customer?root=root

This is the partial result:

<?xml version="1.0" encoding="utf-8" ?> 
<root> 
   <Customer CustomerID="ALFKI" ContactName="Maria Anders" 
             Phone="030-0074321" /> 
   <Customer CustomerID="ANATR" ContactName="Ana Trujillo" 
             Phone="(5) 555-4729" /> 
    ...
</root>
 

See Also

Using Annotated XDR Schemas in Queries

Using XPath Queries

Creating XML Views Using Annotated XDR Schemas