给出以下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..
答案 0 :(得分:1)
此XPath,
//div[@class="a"]//text()[not(parent::div[@class="c"])]
将选择所有没有div
的{{1}}父节点的文本节点:
@class="c"
如果您要排除纯空格文本节点,则此XPath,
some text i want to see
other text i want to see
some more text i wish to see..
将选择这些文本节点,
//div[@class="a"]//text()[not(parent::div[@class="c"]) and normalize-space()]
根据要求。