XML Namespaces

XML on its own, does not hold anything that defines what the data represents about. To let it know, the xml namespace attribute can be added to an element:

    <html xmlns="http://www.w3.org/1999/xhtml">

This indicates that everything between the opening tag <html> and the closing tag </html> is in the http://www.w3.org/1999/xhtml/ namespace. Clicking on http://www.w3.org/1999/xhtml/ pops up a human readable web page, and therefore no computer can check if the content of the xml really follows the definition. To have a computer checking if the data follows a definition, other methods as DTD, XML Schema have to be used. This explains why it is not mandatory to have namespace attributes since a computer can not do a lot with them.

The XML namespace can be understood as a language that defines a set of words. Words not in the dictionary are still possible but do not take part of the language and therefore are subject to cause confusion.

A more complex issue is to have a XML document that makes use of more than one namespace:

  1. An other element within the the html open and close tags might have a xmlns attribute. This results that everything between this child opening and closing tag belongs to the childs namespace (baby language).

  2. However the namespace can also overlap. In this case the tags require prefixes. The following defines with the xmlns attribute the html prefix:

              <html:html xmlns:html="http://www.w3.org/1999/xhtml">

    To know to what namespace the child tag belong, they also require prefixes:

  3. There is also an other way to add a namespace to a tag, just add the uri and not use prefixes


Linurs Servernest startpage