XPath 可以只返回具有 X 子节点的节点吗? [英] Can XPath return only nodes that have a child of X?
本文介绍了XPath 可以只返回具有 X 子节点的节点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用 XPath 仅选择具有特定子元素的节点?例如,从这个 XML 中,我只想要宠物中具有bar"子元素的元素.因此,生成的数据集将包含此示例中的 lizard
和 pig
元素:
Is it possible to use XPath to select only the nodes that have a particular child elements? For example, from this XML I only want the elements in pets that have a child of 'bar'. So the resulting dataset would contain the lizard
and pig
elements from this example:
<pets>
<cat>
<foo>don't care about this</foo>
</cat>
<dog>
<foo>not this one either</foo>
</dog>
<lizard>
<bar>lizard should be returned, because it has a child of bar</bar>
</lizard>
<pig>
<bar>return pig, too</bar>
</pig>
</pets>
这个 Xpath 给了我所有的宠物:"/pets/*"
,但我只想要有一个名为 'bar'
的子节点的宠物.>
This Xpath gives me all pets: "/pets/*"
, but I only want the pets that have a child node of name 'bar'
.
推荐答案
就在这里
/pets/*[bar]
英语:给我所有有孩子 bar
English: Give me all children of pets
that have a child bar
这篇关于XPath 可以只返回具有 X 子节点的节点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文