【问题标题】:xpath expression with namespace带有命名空间的 xpath 表达式
【发布时间】:2013-10-30 06:27:29
【问题描述】:

如果我有这样的 XML 文件:

<abc:persons>
<abc:person id="1">
    ...
</abc:person>
<abc:person id="2">
    ...
</abc:person>
</abc:persons>

鉴于此,如果我想选择 id 为 1 的人,xpath 表达式将是什么。

谢谢。

【问题讨论】:

  • 你已经尝试过......到目前为止,什么?请告诉我,你不是来找人为你写代码的。
  • 您的 XML 文件的命名空间格式不正确。它没有命名空间前缀“abc”的声明。

标签: xml xpath xml-namespaces


【解决方案1】:

尝试搜索元素并使用谓词来区分属性值:

//abc:person[@id = 1]

【讨论】:

    【解决方案2】:

    在 XPath 2 中,您还可以使用:

    //*:person[@id = 1]
    

    如果你不能声明一个命名空间

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-21
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多