【问题标题】:How to select all child nodes except text nodes?如何选择除文本节点之外的所有子节点?
【发布时间】:2013-09-25 20:18:23
【问题描述】:

给定的 XML 看起来像这样

 <FirstChild Orientation="Vertical">
    <SecondChild>Some text</SecondChild>
 </FirstChild>

和一个正在使用的绑定

XPath="child::node()"

我得到的输出看起来像这样

我不希望文本出现在树中

我尝试使用not 喜欢

XPath="child::node()[not(text())]"

还有很多变体,但一直无法确定。

有人知道如何选择所有节点除了文本节点吗?

顺便说一句,我不想​​排除 cmets,只排除文本。

【问题讨论】:

    标签: xml xpath


    【解决方案1】:

    您的 XPath 表达式会排除所有包含文本节点的子节点。

    child::node()[not(text())]
    

    排除属于文本节点的节点它们自己

    child::node()[not(self::text())]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      • 2015-06-29
      • 2012-08-21
      • 1970-01-01
      相关资源
      最近更新 更多