通过XPath

时间:2018-06-19 20:25:22

标签: xml 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"

2 个答案:

答案 0 :(得分:0)

尝试此XPath

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

它将所有description元素与“学习XML”的text()内容匹配,并获得其title

答案 1 :(得分:0)

此XPath,

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

将返回titlefeature/description的书籍中的"Learn XML"个元素。