我知道这是正确的 XML
<Data xmlns="http://w3.schools.com">
<One>Data1</One>
</Data>
xmlns
是一个属性,使用上述语法意味着所有节点都属于双引号中的命名空间。我无法理解的是 xmlns
属性在哪里定义?
最佳答案
参见 Namespaces in XML 1.0 W3C Recommendation xmlns
属性和 xmlns:
前缀的定义。
使用xmlns
的原因总结:
- 使用
xmlns
作为属性来定义一个XML命名空间,它是一个 命名标准旨在让各方独立定义 元素和属性名称的词汇表,同时避免命名 碰撞。 - 使用
xmlns:
作为前缀 定义自定义前缀,XML 命名空间值可以通过简写方式引用。
属性xmlns
属性 xmlns
是一个 reserved attribute并且是 defined as follows :
DefaultAttName ::= 'xmlns'
前缀xmlns:
前缀 xmlns:
是一个 reserved prefix和 defined as follows :
[2] PrefixedAttName ::= 'xmlns:' NCName
另见 Namespace constraint: Reserved Prefixes and Namespace Names
The prefix xmlns is used only to declare namespace bindings and is by definition bound to the namespace name http://www.w3.org/2000/xmlns/. It MUST NOT be declared . Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace. Element names MUST NOT have the prefix xmlns.
引用自XML Recommendation
2.3 Common Syntactic Constructs
Note:
The Namespaces in XML Recommendation [XML Names] assigns a meaning to names containing colon characters. Therefore, authors should not use the colon in XML names except for namespace purposes, but XML processors must accept the colon as a name character.
关于xml - xmlns 属性在哪里定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38634877/