Skip to content

Latest commit

 

History

History
110 lines (91 loc) · 5.09 KB

File metadata and controls

110 lines (91 loc) · 5.09 KB
title Sample annotated XSD Schema for XPath (SQLXML)
description View the annotated XSD schema that is used by the examples in this section to demonstrate XPath queries in SQLXML 4.0.
author MikeRayMSFT
ms.author mikeray
ms.date 03/16/2017
ms.service sql
ms.subservice xml
ms.topic reference
helpviewer_keywords
XPath queries [SQLXML], annotated XSD schemas in queries
annotated XSD schemas, samples
annotated XSD schemas, queries
monikerRange =azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current

Sample Annotated XSD Schema for XPath Examples (SQLXML 4.0)

[!INCLUDE SQL Server Azure 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="http://www.w3.org/2001/XMLSchema"  
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema">  
  <xsd:annotation>  
    <xsd:appinfo>  
      <sql:relationship name="CustOrders"  
                        parent="Sales.Customer"  
                        parent-key="CustomerID"  
                        child="Sales.SalesOrderHeader"  
                        child-key="CustomerID" />  
      <sql:relationship name="OrderOrderDetail"  
                        parent="Sales.SalesOrderHeader"  
                        parent-key="SalesOrderID"  
                        child="Sales.SalesOrderDetail"  
                        child-key="SalesOrderID" />  
    </xsd:appinfo>  
  </xsd:annotation>  
  
  <xsd:element name="Customer" sql:relation="Sales.Customer" type="CustomerType" />  
  
  <xsd:complexType name="CustomerType" >  
     <xsd:sequence>  
        <xsd:element name="Order"   
                     sql:relation="Sales.SalesOrderHeader"  
                     sql:relationship="CustOrders" />  
     </xsd:sequence>  
     <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:complexType>  
  
  <xsd:element name="Order" sql:relation="Sales.SalesOrderHeader" type="OrderType"/>  
  
  <xsd:complexType name="OrderType">  
     <xsd:sequence>  
        <xsd:element name="OrderDetail"   
                     sql:relation="Sales.SalesOrderDetail"  
                     sql:relationship="OrderOrderDetail" />  
     </xsd:sequence>  
     <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:complexType>  
  
  <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:complexType>  
  
  <xsd:element name="UnitPriceDiscount" sql:relation="Sales.SalesOrderDetail" type="DiscountType"/>  
  
  <xsd:complexType name="DiscountType">  
    <xsd:simpleContent>  
       <xsd:extension base="xsd:string">  
          <xsd:anyAttribute namespace="##other" processContents="lax"/>  
       </xsd:extension>  
    </xsd:simpleContent>  
  </xsd:complexType>  
  
  <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"/>  
  </xsd:complexType>  
  
</xsd:schema>