Where is xmlns attribute defined?

时间秒杀一切 提交于 2019-12-08 00:57:48

问题


I know that this is correct XML

<Data xmlns="http://w3.schools.com">
  <One>Data1</One>
</Data>

xmlns is an attribute and using the above syntax means all nodes belong to the namespace in double quotes. What I can't understand is where is xmlns attribute defined?


回答1:


See Namespaces in XML 1.0 W3C Recommendation for the definitions of both the xmlns attribute and xmlns: prefix.

Summary of reasons to use xmlns:

  • Use xmlns as an attribute to define an XML namespace, which is a naming standard designed to allow parties to independently define vocabularies of element and attribute names while avoiding naming collisions.
  • Use xmlns: as a prefix to define a custom prefix by which an XML namespace value can be referenced by shorthand.

Attribute xmlns

The attribute xmlns is a reserved attribute and is defined as follows:

DefaultAttName ::= 'xmlns'

Prefix xmlns:

The prefix xmlns: is a reserved prefix and defined as follows:

[2] PrefixedAttName ::= 'xmlns:' NCName

See also 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.

Reference from 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.



来源:https://stackoverflow.com/questions/38634877/where-is-xmlns-attribute-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!