当前位置:首页 > 网络编程 > WEB编程 > XML编程 > 在XPath查询中指定轴(转自MSSQL手册)

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

点击次数:29 次 发布日期:2008-11-21 22:22:55 作者:源代码网
源代码网推荐

源代码网整理以下以下示例显示如何在 XPath 查询中指定轴。这些示例中的 XPath 查询都在 SampleSchema1.xml 中所包含的映射架构上指定。有关此示例架构的信息,请参见示例 XPath 查询。

源代码网整理以下示例

源代码网整理以下A. 检索上下文节点的子元素

源代码网整理以下此 XPath 查询选定上下文节点的所有 <Customer> 子元素:

源代码网整理以下


/child::Employee

源代码网整理以下在此查询中,child 是轴,Customer 是节点测试(如果 Customer 是 <element> 节点,则该测试为 TRUE,因为 <element> 是与 child 轴相关联的主要节点类型)。 

源代码网整理以下child 是默认轴。因此,可将该查询编写为:

源代码网整理以下


/Employee

源代码网整理以下在映射架构上测试 XPath 查询

源代码网整理以下创建下面的模板 (MyTemplate.xml) 并将其保存在与 template 虚拟名称相关联的目录中。 

源代码网整理以下


<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
  <sql:xpath-query mapping-schema="SampleSchema2.xml">
    /Employee
  </sql:xpath-query>
</ROOT>

源代码网整理以下下面的 URL 执行模板: 
http://IISServer/VirtualRoot/template/MyTemplate.xml

源代码网整理以下可直接在 URL 中指定 XPath 查询:
http://IISServer/nwind/schema/SampleSchema1.xml/child::Customer?root=root

源代码网整理以下虚拟名称 schema 是 schema 类型。架构文件存储在与 schema 类型虚拟名称相关联的目录下。root 参数用于为所得到的 XML 文档指定顶层元素(root 可为任意值)。

源代码网整理以下下面是模板执行的部分结果集:

源代码网整理以下


<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. 检索上下文节点的孙节点

源代码网整理以下此 XPath 查询选定上下文节点的 <Customer> 子元素的所有 <Order> 子元素:

源代码网整理以下


/child::Customer/child::Order

源代码网整理以下在此查询中,child 是轴,Customer 和 Order 是节点测试(如果 Customer 和 Order 是 <element> 节点,则这些节点测试为 TRUE,因为 <element> 节点是 child 轴的主要节点)。对于每个匹配 <Customer> 的节点,将匹配 <Orders> 的节点添加到结果中。结果集中只返回 <Order>。

源代码网整理以下child 是默认轴。因此,可将此查询指定为:

源代码网整理以下


/Customer/Order

源代码网整理以下在映射架构上测试 XPath 查询

源代码网整理以下创建下面的模板 (MyTemplate.xml) 并将其保存在与 template 虚拟名称相关联的目录中。 

源代码网整理以下


源代码网整理以下<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
  <sql:xpath-query mapping-schema="SampleSchema1.xml">
    /Customer/Order
  </sql:xpath-query>
</ROOT>

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华