Xml 当节点文本包含
具有如下所示的文本xml代码:Xml 当节点文本包含,xml,xpath,Xml,Xpath,具有如下所示的文本xml代码: <meters> <metric> <n>one</n> <k>two</k> <m>three</m> <k>four</k> </metric> <metric> <n>one</n>
<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>
T
//n[包含(,“一”)]/
我希望它能退回这样的东西
<k>two</k>
<m>three</m>
<k>four</k>
<k>five</k>
<m>six</m>
<k>seven</k>"
2
三
四
五
六
七“
它被称为“跟随兄弟姐妹”,而不是“跟随兄弟姐妹”。尽管你走对了方向:
//n[contains(., "one")]/following-sibling::*
演示(使用xmllint
):
$xmllint input.xml--xpath'//n[包含(,“一”)]/以下同级::*'
二三四五七
//n[contains(., "one")]/following-sibling::*
$ 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>