XML: avoiding namespace collision

XML namespaces were originally designed to avoid confusion between elements sharing the same characteristics. However, namespace should be created very carefully in order to avoid any possible collision. The first thing you need to bear in mind is that namespaces must have an higher degree of specificity than generic or public namespaces. For example, this is a perfectly valid XML namespace:

<document xmlns="http://www.site.com/ns/document" />

The problem with this namespace, however, is that is too generic, thus allowing for a possible collision. Instead, you should always choose a more specific namespace, for example by using the name of your website or web application, like so:

<document xmlns="http://onwebdev.blogspot.com/ns/elements/document" />

It's still true that other persons can actually use your namespaces on their websites, but it's also true that using a major level of specificity adds more semantics to your namespaces and, consequently, makes the risk of namespace collision less likely. Bear in mind that the purpose of namespaces is not trying to have absolutely unique IDs, but avoiding confusion between resources that may feature similar characteristics.

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Leave a Reply

Note: Only a member of this blog may post a comment.