繁体   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