Namespace

A namespace is used to prevent name clashes of elements and attributes. This can be important when different people are working together, each creating their own XML documents. By convention, an HTTP-style URL is used as a namespace, although no connection to the URL is needed to process the XML document.

A namespace is declared in an opening tag like this:
xmlns:prefixName="namespaceName"

Syntax for declaring a namespace in an opening tag.

A namespace can only be used after it has been declared in an ancestor or current element. To use a namespace, prepend an element name or attribute name with 'prefixName:'.

If the part ':prefixName' is omitted, a default namespace is assumed. The scope of the namespace is the content of the tag itself. To use the default namespace, the descendant element names and attribute names need not be prefixed with any prefix name.

Reserved Prefix Names

The prefix name 'xml' is reserved and bound to 'http://www.w3.org/XML/1998/namespace'. It may be declared, but must not be bound to any other namespace name. Other prefix names must not be bound to this namespace name, and it must not be declared as the default namespace.
The prefix name 'xmlns' is reserved and bound to 'http://www.w3.org/2000/xmlns/'. It must not be declared. Other prefix names must not be bound to this namespace name. It must not be declared as the default namespace. Element names must not have the prefix xmlns.
Prefix names beginning with 'xml' are reserved.


No tag may contain two attributes that have the same names, or the same local names prefixed by prefix names bound to the same namespace name.

With XPath 3.0, XML namespaces may be referenced using braced URI literals. For example, the qualified name math:pi may be expanded to Q{http://www.w3.org/2005/xpath-functions/math}pi, embedding the namespace URI inside the prefix. See XPath.

<?xml version="1.0" encoding="UTF-8"?>
<bookslist xmlns:gb="http://GoldenBookstore.com"
           xmlns:xlink="http://www.w3.org/1999/xlink"
           xmlns:xi="http://www.w3.org/2003/XInclude">
   <gb:book>
      <author gb:gender="f"
              xlink:type="simple"
              xlink:href="/images/jkrowling.gif"
              xlink:show="new">J. K. Rowling</author>
   </gb:book>
</bookslist>