gpt4 book ai didi

xml - 当节点文本包含xPath时获得同级节点

转载 作者:行者123 更新时间:2023-12-03 17:36:38 24 4
gpt4 key购买 nike

具有文本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>"

最佳答案

它称为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>

关于xml - 当节点文本包含xPath时获得同级节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28376732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com