I was wondering why do we have to define our namespaces with an URI that is unique for our organization (just like packages in Java). That would obviously make sense and let us avoid name conflicts. However, this page says:
It is also possible (though not recommended) for the same prefix refer to different namespaces, depending on their context
So basically if I have my own XML document with my own namespace prefix myNamespace
defined as http://hisdomain.com/test
, somebody could redefine the 'myNamespace' prefix to point to his own namespace http://hisdomain.com/test
, even by mistake (I think there is no alert if I define a namespace prefix that has been already defined in the document).
Even with URIs, other people need to make sure they don't use my prefix!
Then using URIs and having to provide definitions to namespaces becomes useless, the namespace system would work equally well if we simply used the prefixes only without having to provide definitions using xlns
attribute.
If I understand correctly, this is not allowed:
<root xmlns:abc="mydomain.com/test" xmlns:abc="yourdomain.com/test">
...
</root>
but this one is okay - you could redefine the abc
prefix with your domain.
<root xmlns:abc="mydomain.com/test">
<body xmlns:abc="yourdomain.com/test">
...//to use my namespace here, I'd need to redefine it again to mydomain.com/test
</body>
</root>