基于子值的 XPath 选择 [英] XPath select based on child value(s)
本文介绍了基于子值的 XPath 选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一些xml:
<books>
<book>
<author>Tom</author>
<genres>
<genre>Science</genre>
<genre>Romance</genre>
</genres>
</book>
<book>
<author>Mike</author>
<genres>
<genre>Politics</genre>
<genre>Romance</genre>
</genres>
</book>
</books>
我如何定义一个 xpath 以便它可以提取所有浪漫书籍?或者也许所有的浪漫和政治书籍?
How can I define an xpath such that it pulls all Romance books? Or maybe all Romance and Politics books?
推荐答案
你可以使用 //book[./genres/genre = 'Romance']
和 //book[./genres/genre = 'Romance' 和 ./genres/genre = 'Politics']
,分别
You can go with //book[./genres/genre = 'Romance']
and //book[./genres/genre = 'Romance' and ./genres/genre = 'Politics']
, respectively
这篇关于基于子值的 XPath 选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文