The default namespace is not named xmlns
.
xmlns
is the way to declare a namespace prefix (i.e. short name, handle). The syntax is xmlns[:prefix]="namepace-uri"
.
There can be exactly one namespace declaration per XML element where you are allowed to leave off the prefix (xmlns="namespace-uri"
), and if it is declared that way, it is called the default namespace.
It's called default because all descendant elements that don't explicitly override it will inherit it - here <element>
, <child>
and the first <grandchild>
are all part of some_namespace
:
<element xmlns="some_namespace">
<child>
<grandchild />
<grandchild xmlns="something_else" />
<yan:grandchild xmlns:yan="yet_another_namespace" />
</child>
</element>
This automatic inheritance does not happen with prefixes - here, only <sn:element>
is in some_namespace
, and therefore identical to the <element>
above, while <child>
and the first <grandchild>
are in no namespace:
<sn:element xmlns:sn="some_namespace">
<child>
<grandchild />
<grandchild xmlns="something_else" />
<yan:grandchild xmlns:yan="yet_another_namespace" />
</child>
</sn:element>
The important part is only the namespace URI, not the prefix:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
declares that the URI http://www.w3.org/2001/XMLSchema-instance
shall be known as xsi
inside this element.
You are free to choose any prefix you like, you can declare xmlns:bob="http://www.w3.org/2001/XMLSchema-instance"
and that would mean that the URI http://www.w3.org/2001/XMLSchema-instance
shall be known as bob
inside this element.
By convention, many widely-used XML namespace URIs get the same prefix everywhere, but that's not technically necessary.