Using Annotated XDR Schemas in Queries (Deprecated in SQLXML 4.0)
Important
This topic is included as a reference for legacy applications. No future development work will be done on this feature. Avoid using this feature in new development work. Instead, use annotated XSD schemas to create XML views. For more information, see Introduction to Annotated XSD Schemas (SQLXML 4.0). You can convert existing annotated XDR schemas to XSD schemas. For more information, see Converting Annotated XDR Schemas to Equivalent XSD Schemas (SQLXML 4.0).
Note
To create working samples using the following examples, you must meet certain requirements. For more information, see Requirements for Running SQLXML Examples.
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.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" sql:id="MyMappingSchema" sql:is-mapping-schema="1"> <ElementType name="Person.Contact" > <AttributeType name="ContactID" /> <AttributeType name="FirstName" /> <AttributeType name="LastName" /> <attribute type="ContactID" /> <attribute type="FirstName" /> <attribute type="LastName" /> </ElementType> </Schema> <sql:xpath-query mapping-schema="#MyMappingSchema"> Person.Contact[@ContactID < 4] </sql:xpath-query> </ROOT>
For illustration purposes, save this template using the file name InlineSchemaTemplate.xml.
See Also
Reference
Using XPath Queries in SQLXML 4.0