Sample Annotated XSD Schema for XPath Examples (SQLXML 4.0)

Applies to: yesSQL Server (all supported versions) YesAzure SQL Database

The sample XPath queries in this section refer to a mapping schema. The mapping schema is an annotated XML Schema (XSD) file. For more information about mapping schemas, see Introduction to Annotated XSD Schemas (SQLXML 4.0).

The following are needed to execute XPath queries against an annotated XSD schema:

  • Create a template with an XPath query in it. In the template, you specify the mapping schema against which the XPath query is to be executed. In this case, the mapping schema must be stored in the directory (or one of its subdirectories, in which case a relative path is specified as the value of the mapping-schema attribute in the template) associated with template file.

  • Create a test application that uses SQLXML extensions for ADO to execute queries. For more information, see Using ADO to Execute SQLXML 4.0 Queries.

In all the examples in this section, for illustration purposes, the XPath queries are specified in a template and the template is executed using ADO. Therefore, you must use the following mapping schema file, SampleSchema1.xml. Save this file in the directory where your templates are stored.

Sample Annotated XSD Schema (SampleSchema1.xml)

<?xml version="1.0"?>  
<xsd:schema xmlns:xsd=""  
      <sql:relationship name="CustOrders"  
                        child-key="CustomerID" />  
      <sql:relationship name="OrderOrderDetail"  
                        child-key="SalesOrderID" />  
  <xsd:element name="Customer" sql:relation="Sales.Customer" type="CustomerType" />  
  <xsd:complexType name="CustomerType" >  
        <xsd:element name="Order"   
                     sql:relationship="CustOrders" />  
     <xsd:attribute name="CustomerID" type="xsd:ID"/>  
     <xsd:attribute name="TerritoryID"/>  
     <xsd:attribute name="AccountNumber"/>  
     <xsd:attribute name="CustomerType"/>  
     <xsd:attribute name="Orders" type="xsd:IDREFS" sql:prefix="Ord-"/>  
  <xsd:element name="Order" sql:relation="Sales.SalesOrderHeader" type="OrderType"/>  
  <xsd:complexType name="OrderType">  
        <xsd:element name="OrderDetail"   
                     sql:relationship="OrderOrderDetail" />  
     <xsd:attribute name="SalesOrderID" type="xsd:ID" sql:prefix="Ord-"/>  
     <xsd:attribute name="SalesPersonID"/>  
     <xsd:attribute name="OrderDate"/>  
     <xsd:attribute name="DueDate"/>  
     <xsd:attribute name="ShipDate"/>  
  <xsd:element name="OrderDetail" sql:relation="Sales.SalesOrderDetail" type="OrderDetailType"/>  
  <xsd:complexType name="OrderDetailType">  
    <xsd:attribute name="ProductID" type="xsd:IDREF"/>  
    <xsd:attribute name="UnitPrice"/>  
    <xsd:attribute name="OrderQty"/>  
    <xsd:attribute name="UnitPriceDiscount"/>  
  <xsd:element name="UnitPriceDiscount" sql:relation="Sales.SalesOrderDetail" type="DiscountType"/>  
  <xsd:complexType name="DiscountType">  
       <xsd:extension base="xsd:string">  
          <xsd:anyAttribute namespace="##other" processContents="lax"/>  
  <xsd:element name="Contact" sql:relation="Person.Contact" type="ContactType"/>  
  <xsd:complexType name="ContactType">  
    <xsd:attribute name="ContactID"/>  
    <xsd:attribute name="LastName"/>  
    <xsd:attribute name="FirstName"/>  
    <xsd:attribute name="Title"/>