The concept of namespaces is similar to defining a variable with same name in different classes and accessing them by prefixing the object name to resolve the naming conflict. In xml document also if you have to define two elements with same tag (which would probably indicate two different things like html table & dining table) then we can use namespaces to resolve the naming conflict.
Namespace is defined by the xmlns attribute either in the start tag of an element or in the document root element as xmlns:prefix="URI". Below is the example:
Defining a default namespace for an element saves us from using prefixes in all the child elements, the syntax is xmlns="namespaceURI". Below is an example:
Namespace is defined by the xmlns attribute either in the start tag of an element or in the document root element as xmlns:prefix="URI". Below is the example:
<root> <h:table h="http://www.w3.org/TR/html4/"> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table f="http://www.w3schools.com/furniture"> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> <root xmlns:h="http://www.w3.org/TR/html4/" xmlns:f="http://www.w3schools.com/furniture"> <!-- Same as above --> </root>The namespace URI is not used by the parser to look up information. The purpose is just to give the namespace a unique name.
Defining a default namespace for an element saves us from using prefixes in all the child elements, the syntax is xmlns="namespaceURI". Below is an example:
<table xmlns="http://www.w3.org/TR/html4/"> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table>