How XML Namespaces Work : Namespace « Namespace « XML Tutorial






To use XML namespaces, elements are given qualified names. 
Qualified name is abbreviated to QName.
These qualified names consist of two parts.
The local part is the same as the names we have been giving elements.
The namespace prefix specifies to which namespace this name belongs. 

For example: 

<pers:person xmlns:pers="http://www.java2s.com"/> 

xmlns stands for XML Namespace. 
pers is the namespace prefix.
http://www.java2s.com is the URI of the namespace. 
Prefix itself (pers) doesn't have any meaning - its only purpose is to point to the namespace name. 
The prefix is needed on both the start-tags and end-tags of the elements. 
The elements are no longer simply being identified by their names, but by their QNames. 
This prefix can be used for any descendants of the <pers:person> element to denote that they also belong to the http://www.java2s.com namespace.

<pers:person xmlns:pers="http://www.java2s.com">
  <pers:name>
    <pers:title>Sir</pers:title>
  </pers:name>
</pers:person>








2.1.Namespace
2.1.1.Why We Need Namespaces
2.1.2.How XML Namespaces Work
2.1.3.Default Namespaces
2.1.4.Declaring Namespaces on Descendants
2.1.5.Understanding URIs
2.1.6.Change URI of namespace
2.1.7.Using Prefixes