a namespace is a set of unique names. namespace is a mechanisms by which element and attribute name can be assigned to a group. the namespace is identified by uri(uniform resource identifiers).
namespace declaration
a namespace is declared using reserved attributes. such an attribute name must either be xmlns or begin with xmlns: shown as below −
<element xmlns:name = "url">
syntax
the namespace starts with the keyword xmlns.
the word name is the namespace prefix.
the url is the namespace identifier.
example
namespace affects only a limited area in the document. an element containing the declaration and all of its descendants are in the scope of the namespace. following is a simple example of xml namespace −
<?xml version = "1.0" encoding = "utf-8"?> <cont:contact xmlns:cont = "www.tutorialspoint.com/profile"> <cont:name>tanmay patil</cont:name> <cont:company>tutorialspoint</cont:company> <cont:phone>(011) 123-4567</cont:phone> </cont:contact>
here, the namespace prefix is cont, and the namespace identifier (uri) as www.tutorialspoint.com/profile. this means, the element names and attribute names with the cont prefix (including the contact element), all belong to the www.tutorialspoint.com/profile namespace.