在XPath查询中指定轴(转自MSSQL手册)

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

以下示例显示如何在 XPath 查询中指定轴。这些示例中的 XPath 查询都在 SampleSchema1.xml 中所包含的映射架构上指定。有关此示例架构的信息,请参见示例 XPath 查询。 
示例 
A. 检索上下文节点的子元素 
此 XPath 查询选定上下文节点的所有 子元素: 
/child::Employee 
在此查询中,child 是轴,Customer 是节点测试(如果 Customer 是 节点,则该测试为 TRUE,因为 是与 child 轴相关联的主要节点类型)。  
child 是默认轴。因此,可将该查询编写为: 
/Employee 
在映射架构上测试 XPath 查询 
创建下面的模板 (MyTemplate.xml) 并将其保存在与 template 虚拟名称相关联的目录中。  

 
   
    /Employee 
   
Copy after login

下面的 URL 执行模板:

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

可直接在 URL 中指定 XPath 查询:

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

虚拟名称 schema 是 schema 类型。架构文件存储在与 schema 类型虚拟名称相关联的目录下。root 参数用于为所得到的 XML 文档指定顶层元素(root 可为任意值)。
下面是模板执行的部分结果集:

  
    
    
   ... 
Copy after login

B. 检索上下文节点的孙节点
此 XPath 查询选定上下文节点的 子元素的所有 子元素:
/child::Customer/child::Order
在此查询中,child 是轴,Customer 和 Order 是节点测试(如果 Customer 和 Order 是 节点,则这些节点测试为 TRUE,因为 节点是 child 轴的主要节点)。对于每个匹配 的节点,将匹配 的节点添加到结果中。结果集中只返回
child 是默认轴。因此,可将此查询指定为:
/Customer/Order
在映射架构上测试 XPath 查询
创建下面的模板 (MyTemplate.xml) 并将其保存在与 template 虚拟名称相关联的目录中。

 
   
    /Customer/Order 
   
Copy after login

 以上就是在XPath查询中指定轴(转自MSSQL手册)的内容,更多相关内容请关注PHP中文网(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 [email protected]
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!