XML and Internet Support

Sample XPath Queries

The sample XPath queries refer to the following mapping schema. The mapping schema is an annotated XML-Data Reduced (XDR) schema. For more information about mapping schemas, see Creating XML Views Using Annotated XDR Schemas.

Note  Before you can execute the sample XPath queries using a URL, you must create a virtual root to access the Northwind database and the virtual names of template and schema types. For information about creating the sample nwind virtual directory and the virtual names, see Creating the nwind Virtual Directory. For more information about accessing Microsoft® SQL Server™ using HTTP, see Accessing SQL Server Using HTTP.

There are two ways to execute XPath queries against the annotated XDR schemas:

Sample Annotated XDR Schema

In all the examples in this section, for illustration purposes, the XPath queries are specified in a template and the template is executed using HTTP. Therefore, you must use this mapping schema file, (SampleSchema1.xml), which is saved in the directory associated with virtual name of template type:

<?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" dt:type="id" />
    <AttributeType name="CompanyName" />
    <AttributeType name="ContactName" />
    <AttributeType name="City" />
    <AttributeType name="Fax" />
    <AttributeType name="Orders" dt:type="idrefs"  sql:id-prefix="Ord-" />

    <attribute type="CustomerID" />
    <attribute type="CompanyName" />
    <attribute type="ContactName" />
    <attribute type="City" />
    <attribute type="Fax" />
    <attribute type="Orders" sql:relation="Orders" sql:field="OrderID">
      <sql:relationship  
                key-relation="Customers"  
                key="CustomerID"
                foreign-relation="Orders" 
                foreign-key="CustomerID" />
    </attribute>

    <element type="Order">
      <sql:relationship 
               key-relation="Customers"  
               key="CustomerID"
               foreign-relation="Orders" 
               foreign-key="CustomerID" />
    </element>
  </ElementType>

  <ElementType name="Order" sql:relation="Orders">
    <AttributeType name="OrderID" dt:type="id" sql:id-prefix="Ord-" />
    <AttributeType name="EmployeeID" />
    <AttributeType name="OrderDate" />
    <AttributeType name="RequiredDate" />
    <AttributeType name="ShippedDate" />

    <attribute type="OrderID" />
    <attribute type="EmployeeID" />
    <attribute type="OrderDate" />
    <attribute type="RequiredDate" />
    <attribute type="ShippedDate" />

    <element type="OrderDetail">
      <sql:relationship 
                 key-relation="Orders"              
                 key="OrderID"
                 foreign-relation="[Order Details]" 
                 foreign-key="OrderID" />
    </element>
  </ElementType>

  <ElementType name="OrderDetail" sql:relation="[Order Details]"
                                  sql:key-fields="OrderID ProductID">
    <AttributeType name="ProductID" dt:type="idref" 
                                    sql:id-prefix="Prod-" />
    <AttributeType name="UnitPrice"/>
    <AttributeType name="Quantity" />

    <attribute type="ProductID" />
    <attribute type="UnitPrice" sql:field="UnitPrice" />
    <attribute type="Quantity" />

    <element type="Discount"  sql:field="Discount"/>
  </ElementType>

  <ElementType name="Discount" dt:type="string" 
                               sql:relation="[Order Details]"/>

<ElementType name="Employee" sql:relation="Employees">
    <AttributeType name="EmployeeID" />
    <AttributeType name="LastName" />
    <AttributeType name="FirstName" />
    <AttributeType name="Title" />

    <attribute type="EmployeeID" />
    <attribute type="LastName" />
    <attribute type="FirstName" />
    <attribute type="Title" />
</ElementType>
</Schema>

Note  

The sample queries are grouped by the type of XPath operation that is performed by the query.