与 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/n1
在 root
元素和 foo
元素的范围内,但是不适用于 bar
元素,因为它有自己的默认命名空间声明,覆盖了外部范围之一。然而,命名空间声明 xmlns:pf2="http://example.com/ns2"
在根元素及其所有后代的范围内。
关于xml - 什么是与 XPath 相关的范围内命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4384203/