【发布时间】:2012-06-13 01:38:44
【问题描述】:
这个问题是Can XPath return only nodes that have a child of X?的延续。
我想找到所有有 foo 的“宠物”,其中一些宠物有命名空间而其他宠物没有。
是否可以使用 XPath 仅选择具有特定子元素的节点?例如,从这个 XML 中,我只想要 pets 中具有“bar”子项的元素。因此生成的数据集将包含蜥蜴和猪元素。
<pets xmlns="urn:cat-org:v1">
<cat>
<foo>don't care about this</foo>
</cat>
<dog xmlns:v1="urn:cat-org:v1">
<v1:foo>not this one either</foo>
</dog>
<lizard>
<bar>lizard should be returned, because it has a child of bar</bar>
</lizard>
<pig xmlns:v55="urn:cat-org:v1">
<v55:bar>return pig, too</bar>
</pig>
</pets>
任何建议都会动摇。
【问题讨论】: