在 XPath 查詢中指定軸(轉自MSSQL手冊)

來源:互聯網
上載者:User
sql 以下樣本顯示如何在 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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.