XML technologies / XML / XML in a Nutshell / Namespaces

(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)

Namespaces serve two purposes in XML:

  1. They distinguish elements and attributes that share a name but have different meanings in different vocabularies.

  2. They group all elements and attributes of an XML application so that software can recognize them easily.

The first purpose is easier to explain and understand, but the second is more important in practice.

Namespaces are created by placing a prefix before each element and attribute. Each prefix is mapped to a URI using an xmlns:praefix attribute. Default URIs can also be specified for elements without a prefix. Default namespaces are declared using xmlns attributes. Elements and attributes associated with the same URI belong to the same namespace. The elements of many XML applications are identified by standard URIs.

In an XML 1.1 document, an Internationalized Resource Identifier (IRI) can be used instead of a URI. An IRI is like a URI except that it can contain non-ASCII characters such as é and π. In practice, parsers do not check whether namespace names are valid XML 1.0 URIs, so this distinction is largely theoretical.

  

  

 

 

 

back to top