xml - 什么是与 XPath 相关的范围内命名空间?

标签 xml xpath

与 XPath 相关的范围内命名空间究竟是什么?

谢谢

最佳答案

对于 XSLT/XPath 1.0 数据模型,http://www.w3.org/TR/xpath/#namespace-nodes 中的 XPath 1.0 规范以下是关于 namespace nodes 的内容:

Each element has an associated set of namespace nodes, one for each distinct namespace prefix that is in scope for the element (including the xml prefix, which is implicitly declared by the XML Namespaces Recommendation [XML Names]) and one for the default namespace if one is in scope for the element.

命名空间声明及其范围在 XML 命名空间规范中定义,http://www.w3.org/TR/xml-names/#scoping说:

The scope of a namespace declaration declaring a prefix extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner declarations with the same NSAttName part. In the case of an empty tag, the scope is the tag itself.

Such a namespace declaration applies to all element and attribute names within its scope whose prefix matches that specified in the declaration.

http://www.w3.org/TR/xml-names/#defaulting以下是关于任何默认命名空间声明的范围(即 xmlns="http://example.com/ns1):

The scope of a default namespace declaration extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner default namespace declarations. In the case of an empty tag, the scope is the tag itself.

举个例子,用

<root xmlns="http://example.com/n1" xmlns:pf2="http://example.com/ns2">
  <foo>
    <bar xmlns="http://example.com/ns3">whatever</bar>
  </foo>
</root>

默认命名空间声明 http://example.com/n1root 元素和 foo 元素的范围内,但是不适用于 bar 元素,因为它有自己的默认命名空间声明,覆盖了外部范围之一。然而,命名空间声明 xmlns:pf2="http://example.com/ns2" 在根元素及其所有后代的范围内。

关于xml - 什么是与 XPath 相关的范围内命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4384203/

相关文章:

c# - LINQ 读取 XML

xml - 属性错误 : type object 'ElementTree' has no attribute 'tostring'

java - Adobe 体验管理器 6.2

sql - SQL for XML Path使用节点名称和嵌套的数据值

c# - 如何只获取没有样式属性的 div?

java - 如何使用 java 中的 vtd-xml 将新元素附加到现有 xml

c# - 读取ISO 8859 1编码,用webclient下载xml流

java - 需要一些有关 XPath 表达式的帮助。一个有效,另一个无效

html - 找不到 Chrome DevTools 给出的 XPath

javascript - 是否可以获取元素的 css?