【问题标题】:XPath select nodes with attribute namesXPath 选择具有属性名称的节点
【发布时间】:2016-08-11 04:17:04
【问题描述】:

假设我们有一个 XML 文档

<MyDocument>
<Pages>
    <Page>
        <Para>
            <Word show="yes" wo="2">Some</Word>
            <Word>People</Word>
        </Para>
    </Page>
    <Page>
        <Para>
            <Word>Some</Word>
            <Word show="yes">Other</Word>
            <Word show="yes" wo="1">People</Word>
        </Para>
    </Page>
</Pages>
</MyDocument>

我们怎样才能找到所有具有'show'和'wo'属性的Word节点?我试过 XPath //[@show] | //[@wo] 但这个表达式也选择带有@show 的节点。并且 //*[@show @wo] 不是合法表达式。

谢谢

【问题讨论】:

    标签: xml xpath


    【解决方案1】:

    我们怎样才能找到所有具有'show'和'wo'属性的Word节点?

    使用and:

    //Word[@show and @wo]
    

    或者,您也可以在单独的方括号中包含多个条件:

    //Word[@show][@wo]
    

    【讨论】:

      猜你喜欢
      • 2013-11-30
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 2015-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多