Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.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
String Xpath选择节点文本但排除子节点文本_String_Xpath_Tags - Fatal编程技术网

String Xpath选择节点文本但排除子节点文本

String Xpath选择节点文本但排除子节点文本,string,xpath,tags,String,Xpath,Tags,我有以下XML: <topic class="Top"> <title> Interesting Article </title> <subtitle> Science & Industry <insertedText action="start"/> Inside & Out <insertedText

我有以下XML:

<topic class="Top">
    <title>
        Interesting Article
    </title>
    <subtitle>
        Science & Industry
        <insertedText action="start"/>
            Inside & Out
        <insertedText action="end"/>
        A Profile
    </subtitle>
</topic>
回答

根据@lambo477提供的答案,完整答案如下:

./topic[@class='top']/*[local-name()='subtitle']/text()[1]|/topic[@class='top']/*[local-name()='subtitle']/*[local-name()='insertedText'][@action='end']/following-sibling::node()[1]

您可以尝试以下XPath:

//subtitle/text()[1]|//insertedText[@action="end"]/following-sibling::node()[1]

您可以尝试以下XPath:

//subtitle/text()[1]|//insertedText[@action="end"]/following-sibling::node()[1]

谢谢@lambo477,不过我已经编辑了我的OP来澄清,节点的数量也是可变的。我认为我的解决方案应该以任何一种方式工作?它将在孩子们点头之前和之后选择文本Sah yes@lambo477,我现在看到了。尽管在某些情况下,标签的数量可能超过一个或没有!为了清晰起见,我再次扩展了我的OP,再次感谢。希望的输出是什么?例如,2?我的解决方案也适用于有0、1或>1个子元素的情况,因此我看不到问题!谢谢@lambo477,不过我已经编辑了我的OP来澄清,节点的数量也是可变的。我认为我的解决方案应该以任何一种方式工作?它将在孩子们点头之前和之后选择文本Sah yes@lambo477,我现在看到了。尽管在某些情况下,标签的数量可能超过一个或没有!为了清晰起见,我再次扩展了我的OP,再次感谢。希望的输出是什么?例如,2?我的解决方案也适用于有0、1或>1个子元素的情况,因此我看不到问题!