Sunday, January 13, 2008

A Tutorial on XML Namespaces

XML namespaces are used to avoid element name conflicts. A namespace is a set of names in which all names are unique. An XML namespace can be tought as a Java package name. To distinguish two classes of the same name we put the classes in two different packages. For example; you may choose to put a class that is used to connect to a relational database system in package ( and a class that manages TCP/IP socket connections in package (

An XML namespace is used in the same way. Namespaces make it easier to come up with unique names. Without namespaces all XML element names must be unique all over the world. I'll try to explain this with an example.

Xml representation of a java class.


Xml representation of a college class.

<name>Mathematics 1</name>

If these two "class" XML elements are used in the same XML document there will a name conflict. These name conflicts can be resolved by using namespaces.

<j:class xmlns:j="">

<itu:class xmlns:itu="">
<itu:name>Mathematics 1</itu:name>

ITU : Istanbul Technical University

XML namespaces are defined with XML Namespace (xmlns) Attribute. The XML namespace attribute is placed in the start tag of an element and has the following syntax:


When a namespace is defined in the start tag of an element, all child elements with the same prefix are associated with the same namespace.
If this tutorial is not enough for you can read these articles:
  • Xml namespaces from w3schools
  • Understanding XML Namespaces from Micro$oft MSDN library
  • XML Namespaces by Example from
  • Xml namespaces from wikipedia
  • XML Schema: Understanding Namespaces from Oracle


    CresceNet said...

    Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my site, it is about the CresceNet, I hope you enjoy. The address is . A hug.