拥有如下的文本xml代码:
<meters>
<metric>
<n>one</n>
<k>two</k>
<m>three</m>
<k>four</k>
</metric>
<metric>
<n>one</n>
<k>five</k>
<m>six</m>
<k>seven</k>
</metric>
<metric>
<n>two</n>
<k>eight</k>
<m>nine</m>
<k>ten</k>
</metric>
</meters>
我想得到节点'n'包含文本“one”的所有兄弟节点文本。
尝试:
//*[contains(text(),"one")]/follow-sibling::*/
//*[contains(.,"one")]/follow-sibling::*/
Ť // N [含有(。, “一个”)] /
我希望它返回类似这样的内容
<k>two</k>
<m>three</m>
<k>four</k>
<k>five</k>
<m>six</m>
<k>seven</k>"
答案 0 :(得分:2)
它被称为following-sibling
,而不是follow-sibling
。虽然你走在正确的轨道上:
//n[contains(., "one")]/following-sibling::*
演示(使用xmllint
):
$ xmllint input.xml --xpath '//n[contains(., "one")]/following-sibling::*'
<k>two</k><m>three</m><k>four</k><k>five</k><m>six</m><k>seven</k>