Export (0) Print
Expand All

Using Annotated XDR Schemas in Queries

SQL Server 2000

These are the ways queries can be specified against annotated schema to retrieve data from the database:

  • Specify XPath queries in a template against the XDR schema

    The <sql:xpath-query> element allows you to specify an XPath query against the XML view defined by the annotated schema. The annotated schema against which the XPath query is to be executed is identified by using mapping-schema attribute of the <sql:xpath-query> element.

    Templates are valid XML documents that contain one or more queries. The FOR XML and XPath queries return a document fragment. Templates act as containers for the resulting document fragments (templates provide a way to specify a single, top-level element).

    The examples in this topic use templates to specify an XPath query against an annotated schema to retrieve data from the database.

    For more information about templates, see Executing Template Files Using a URL.

  • Inline Mapping Schemas

    An annotated schema can be included directly in a template. The sql:is-mapping-schema annotation is used to specify an inline annotated schema. sql:is-mapping-schema takes a Boolean type value (0 = FALSE, 1 = TRUE). sql:is-mapping-schema is specified on the <Schema> element in the template.

    The sql:id attribute uniquely identifies the element in which it is contained. sql:id is of the ID type attribute and is specified on the <Schema> element. The value assigned to sql:id is then used to reference the inline annotated schema using the mapping-schema attribute in <sql:xpath-query>.

    For example, this is a template with an inline annotated schema is specified:

    <ROOT     xmlns:sql="urn:schemas-microsoft-com:xml-sql">
      <Schema xmlns="urn:schemas-microsoft-com:xml-data"
        <ElementType name="Employees" >
          <AttributeType name="EmployeeID" />
          <AttributeType name="FirstName" />
          <AttributeType name="LastName" />
          <attribute type="EmployeeID" />
          <attribute type="FirstName" />
          <attribute type="LastName" />
    <sql:xpath-query mapping-schema="#MyMappingSchema">

    For illustration purposes, this template is stored in the template subdirectory of the virtual root directory, and the file name is InlineSchemaTemplate.xml.

    This URL executes the template:


    In the URL, template is a virtual name (created by using the IIS Virtual Directory Management for SQL Server utility) of the template type, followed by the template file name.

  • Mapping Schema in the URL

    An XPath query can be specified against the annotated schema directly in a URL. This is performed by creating a virtual name of schema type and by specifying the annotated schema and the XPath query at the URL.

    For example, consider this annotated schema:

    <?xml version="1.0" ?>
    <Schema xmlns="urn:schemas-microsoft-com:xml-data"
      <ElementType name="Customer" sql:relation="Customers" >
        <AttributeType name="CustomerID" />
        <AttributeType name="ContactName" />
        <AttributeType name="Phone" />
        <attribute type="CustomerID" />
        <attribute type="ContactName" />
        <attribute type="Phone" />

    For illustration purposes, this XDR schema is stored in the schema subdirectory of the virtual root directory, and the file name is Schema2.xml.

    An XPath query against the annotated schema can be specified directly in the URL:


    In the URL, schema is the virtual name of schema type (created by using the IIS Virtual Directory Management for SQL Server utility). Schema2.xml is the annotated schema file followed by an XPath query requesting all the customers with a CustomerID of ALFKI.

See Also

IIS Virtual Directory Management for SQL Server

Using XPath Queries

Accessing SQL Server Using HTTP

Executing Template Files Using HTTP

XML Error Messages

© 2015 Microsoft