簡體   English   中英

通過XPath根據條件獲取XML值

[英]Get XML value based on condition via XPath

以下是我的XML:

<bookstore>
   <book>
      <title>Python</title>
      <price>29.99</price>
   </book>
   <book>
      <title>XML</title>
      <price>29.99</price>
      <feature>
           <description>Learn XML</description>
      </feature>
   </book>
</bookstore>

如果description "Learn XML"匹配,則應返回title "XML"

試試這個XPath

//description[text() = 'Learn XML']/../../title

它將所有description元素與“ Learn XML”的text()內容匹配,並獲得其title

這個XPath

//book[feature/description="Learn XML"]/title

將返回feature/description"Learn XML"的書籍的title元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM