When using prefixes in XML, also-called namespace for the prefix must be defined.The namespace is defined by the xmlns attribute in the start tag of an element.
The namespace declaration has the following syntax. xmlns:prefix="URI".
<root>
<x:book xmlns:x="http://www.tibco.com/abc/dfg/">
<x:index>
<x:chapter>second</x:chapter>
<x:page>thirty</x:page>
</x:index>
</x:book>
<y:book xmlns:y="http://www.tibcoworldin.com/test">
<y:author>African Coffee Table</y:author>
<y:price>90</y:price>
<y:publisher>INX</y:publisher>
</y:book>
</root>
In the example above, the xmlns attribute in the <book> tag give the x: and y: prefixes a qualified namespace.
Default Namespaces
Defining a default namespace for an element saves us from using prefixes in all the child elements.
It has the following syntax:
<x:index>
<x:chapter>second</x:chapter>
<x:page>thirty</x:page>
</x:index>
</x:book>
<y:book xmlns:y="http://www.tibcoworldin.com/test">
<y:author>African Coffee Table</y:author>
<y:price>90</y:price>
<y:publisher>INX</y:publisher>
</y:book>
</root>
In the example above, the xmlns attribute in the <book> tag give the x: and y: prefixes a qualified namespace.
Default Namespaces
Defining a default namespace for an element saves us from using prefixes in all the child elements.
It has the following syntax:
xmlns="namespaceURI"
This XML carries HTML book information:
<book xmlns="http://www.tibco.com/abc/dfg/">
<index>
<chapter>second</chapter>
<page>thirty</page>
</index>
</book>
This XML carries information about a Book (price details):
<book xmlns ="http://www.tibcoworldin.com/test>
<author>African Coffee Table</author>
<price>90</price>
<publisher>INX</publisher>
</book>
This XML carries HTML book information:
<book xmlns="http://www.tibco.com/abc/dfg/">
<index>
<chapter>second</chapter>
<page>thirty</page>
</index>
</book>
This XML carries information about a Book (price details):
<book xmlns ="http://www.tibcoworldin.com/test>
<author>African Coffee Table</author>
<price>90</price>
<publisher>INX</publisher>
</book>