[英]Get XML value based on condition via XPath
Below is my XML: 以下是我的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>
If the description
"Learn XML"
is matched, then it should return the title
"XML"
. 如果
description
"Learn XML"
匹配,则应返回title
"XML"
。
Try this XPath 试试这个XPath
//description[text() = 'Learn XML']/../../title
It matches all description
elements with text()
content of "Learn XML" and gets its title
. 它将所有
description
元素与“ Learn XML”的text()
内容匹配,并获得其title
。
This XPath, 这个XPath
//book[feature/description="Learn XML"]/title
will return title
elements of books whose feature/description
is "Learn XML"
. 将返回
feature/description
为"Learn XML"
的书籍的title
元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.