3

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?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Saurav
  • 592
  • 4
  • 21
  • 1
    Well I have gone through the answers in stack overflow. I have understood that attribute is actually used to bind a namespace in xml. However my question from where does this attribute available in every xml file. From what i have learnt that attribute when having a specific meaning or purpose is binded to a namespace and can be used only when that namespace is defined in xml file – Saurav Jul 28 '16 at 11:23
  • Then you should notice *"URI that needs to be unique so as to indicate that it is a separate namespace from others and any potential duplicate tags will therefore be interpreted correctly. **So the URI will often point to nothing**."* – Marcin Orlowski Jul 28 '16 at 11:25
  • Not sure what you mean by "where is xmlns defined", but the spec is here: https://www.w3.org/TR/2006/REC-xml-names-20060816/ – lesscode Jul 28 '16 at 11:30
  • Hi Wayne, the abstract reads like this "XML namespaces provide a simple method for qualifying element and attribute names used in Extensible Markup Language documents by associating them with namespaces identified by URI references." My question is if xmlns is an attribute then where is it defined?? Which namespace contains that attribute?? – Saurav Jul 28 '16 at 11:38

1 Answers1

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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240