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.java2java.com"/>
xmlns stands for XML Namespace.
pers is the namespace prefix.
http://www.java2java.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.java2java.com namespace.
<pers:person xmlns:pers="http://www.java2java.com">
<pers:name>
<pers:title>Sir</pers:title>
</pers:name>
</pers:person>
|