To specify an axis in an XPath query (go from the MSSQL manual)

Source: Internet
Author: User
Tags manual mssql sql query xmlns xpath
SQL The following example shows how to specify an axis in an XPath query. The XPath queries in these examples are specified on the mapping schema contained in the SampleSchema1.xml. For information about this sample schema, see the sample XPath query.
Example
A. Retrieving child elements of a context node
This XPath queries all <Customer> child elements of the selected context node:
/child::employee
In this query, the child is an axis and the customer is a node test (if the customer is a <element> node, the test is TRUE because <element> is the primary node type associated with the child axis).
The child is the default axis. Therefore, you can write the query as:
/employee
To test an XPath query on the mapping schema
Create the following template (MyTemplate.xml) and save it in the directory associated with the template virtual name.
<root xmlns:sql= "Urn:schemas-microsoft-com:xml-sql" >
<sql:xpath-query mapping-schema= "Sampleschema2.xml" >
/employee
</sql:xpath-query>
</ROOT>
The following URL executes the template:
Http://IISServer/VirtualRoot/template/MyTemplate.xml
XPath queries can be specified directly in the URL:
Http://IISServer/nwind/schema/SampleSchema1.xml/child::Customer?root=root
The virtual name schema is a schema type. The schema file is stored in the directory associated with the schema type virtual name. The root parameter is used to specify the top-level element (root can be any value) for the resulting XML document.
The following is a partial result set for template execution:
<root xmlns:sql= "Urn:schemas-microsoft-com:xml-sql" >
<employee employeeid= "1" lastname= "Davolio"
Firstname= "Nancy" title= "Sales representative"/>
<employee employeeid= "2" lastname= "Fuller"
Firstname= "Andrew" title= "Vice President, Sales"/>
...
</ROOT>
B. Retrieving the grandchild node of a context node
This XPath queries all <Order> child elements of the <Customer> child elements of the selected context node:
/child::customer/child::order
In this query, the child is an axis, and the customer and order are node tests (if the customer and order are <element> nodes, the nodes are tested to TRUE because the <element> node is the child The main node of the axis). For each matching <Customer> node, add the node matching <Orders> to the result. Only <Order> is returned in the result set.
The child is the default axis. Therefore, you can specify this query as:
/customer/order
To test an XPath query on the mapping schema
Create the following template (MyTemplate.xml) and save it in the directory associated with the template virtual name.
<root xmlns:sql= "Urn:schemas-microsoft-com:xml-sql" >
<sql:xpath-query mapping-schema= "SampleSchema1.xml" >
/customer/order
</sql:xpath-query>
</ROOT>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.