Specifying axis in XPath query (reprinted from MSSQL manual)

黄舟
Release: 2017-03-01 16:48:38
Original
1895 people have browsed it

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 SampleSchema1.xml. For information about this sample schema, see Sample XPath Query.
Example
A. Retrieve the child elements of the context node
This XPath queries all child elements of the selected context node:
/child::Employee
In this query, child is the axis and Customer is the node test (this test is TRUE if Customer is an node because is the primary node type associated with the child axis).
child is the default axis. Therefore, the query can be written as:
/Employee
Testing the 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>
Copy after login

The following URL executes the template:

http://IISServer/VirtualRoot/template/MyTemplate.xml
Copy after login

XPath query can be specified directly in the URL:

http://IISServer/nwind/schema/SampleSchema1.xml/child::Customer?root=root
Copy after login

The virtual name schema is the schema type. Schema files are stored in the directory associated with the schema type virtual name. The root parameter specifies the top-level element for the resulting XML document (root can be any value).
The following is a partial result set of 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>
Copy after login

B. Retrieve the grandchild nodes of the context node
This XPath queries all < of the child elements of the selected context node ;Order> Child elements:
/child::Customer/child::Order
In this query, child is the axis, Customer and Order are node tests (if Customer and Order are nodes, then These nodes test TRUE because the node is the primary node of the child axis). For each node that matches , a node that matches is added to the result. Only is returned in the result set.
child is the default axis. Therefore, this query can be specified as:
/Customer/Order
Testing the XPath query on the mapping schema
Create the following template (MyTemplate.xml) and save it in the in the directory.

<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"> 
  <sql:xpath-query mapping-schema="SampleSchema1.xml"> 
    /Customer/Order 
  </sql:xpath-query> 
</ROOT>
Copy after login

The above is the content of specifying the axis in the XPath query (reprinted from the MSSQL manual). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!