Delen via


Voorbeeld geannoteerd XSD-schema voor XPath-voorbeelden (SQLXML 4.0)

Van toepassing op:SQL ServerAzure SQL Database

De voorbeeld-XPath-queries in deze sectie verwijzen naar een mappingschema. Het mappingschema is een geannoteerd XML Schema (XSD)-bestand. Voor meer informatie over mapping schema's, zie Introduction to Annotated XSD Schemas (SQLXML 4.0).

Het volgende is nodig om XPath-queries uit te voeren tegen een geannoteerd XSD-schema:

  • Maak een sjabloon met een XPath-query erin. In het sjabloon specificeer je het mappingschema waarop de XPath-query moet worden uitgevoerd. In dit geval moet het mapping-schema worden opgeslagen in de map (of een van de subdirectories, waarbij een relatief pad wordt gespecificeerd als de waarde van het mapping-schema-attribuut in het template) dat aan het templatebestand is gekoppeld.

  • Maak een testapplicatie die SQLXML-extensies gebruikt zodat ADO queries kan uitvoeren. Zie ADO gebruiken om SQLXML 4.0-query's uit te voeren voor meer informatie.

In alle voorbeelden in deze sectie zijn de XPath-queries ter illustratie gespecificeerd in een sjabloon en wordt het sjabloon uitgevoerd met ADO. Daarom moet je het volgende mapping schema-bestand gebruiken, SampleSchema1.xml. Sla dit bestand op in de map waar je sjablonen worden opgeslagen.

Voorbeeld geannoteerd 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>