Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 当节点文本包含_Xml_Xpath - Fatal编程技术网

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>

具有如下所示的文本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>
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>