繁体   English   中英

如何使用XPath选择除单个节点之外的所有文本?

[英]How to select all text excluding a single node using XPath?

给定以下XML:

<div class="a">
    some text i want to see
    <div class="b">
        other text i want to see
    <div>
    <div class="c">
        some text i DON'T WANT to see
    </div>  
    some more text i wish to see..
</div>

我希望有一个XPATH可以选择所有不在类c下的文本。

预期产量:

some text i want to see
other text i want to see
some more text i wish to see..

这个XPath

//div[@class="a"]//text()[not(parent::div[@class="c"])]

将选择所有没有@class="c"div父节点的文本节点:

some text i want to see
other text i want to see

some more text i wish to see..

如果您要排除纯空格文本节点,请使用此XPath,

//div[@class="a"]//text()[not(parent::div[@class="c"]) and normalize-space()]

将选择这些文本节点,

some text i want to see
other text i want to see
some more text i wish to see..

按照要求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM