Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to figure out why we need URIs for XML namespaces and I cannot find a purpose for that. Can anyone brighten me a little showing their use on a concrete example?


Ok so for instance: I have this from w3schools



   <f:name>African Coffee Table</f:name>


So what should hold ?

share|improve this question
Obligatory w3fools comment. – Yannis Nov 28 '11 at 4:04
So does XML namespaces have to be in a URI format? Or can I just use any string like 'My.Namespace.Foo'? – Mas Jan 17 '12 at 13:07
up vote 14 down vote accepted

A namespace is a way of saying "This kind of Foo" is different from "That kind of Foo", even though they are spelled the same. Or, if you prefer "MY kind of Foo" is different from "Everybody elses kind of Foo".

The technical way of saying this is "The URI of my namespace for Foo" is different from everybody elses URI for their namespace for Foo. In other words, URI's are just strings that allow you to say so.

The trick is then to say, "Hey, URL's are valid URI's", and then use a URI corresponding to a URL under your control. If everybody do that, then you avoid accidental namespace collisions. You could as well have said namespace "A" and namespace "B", but you risk that somebody else would use the same namespace too, and then your kind of Foo is not different from their Foo anymore which is exactly what you want to avoid.

You can then add additional convention to the URLs used as URI's, for instance that the URL must correspond to a page containing documentation or XSD's or similar, but this is not necessary. It is just convenient.

share|improve this answer
Ok, but what's a difference between namespace A and namespace ? both of them can be used by users without them knowing that they have used the same namespaces. – Patryk Nov 28 '11 at 4:14
@Patryk, that is why you use a URL you have control over. The xhtml namespace URL is under control of W3C who defined the XHTML specification. – user1249 Nov 28 '11 at 4:24
@Patryk, also note that it is the ones defining the namespace that gets to pick the URL. Then everybody else can use them. – user1249 Nov 28 '11 at 5:07
So namespace a would totally be valid? Stupid, but valid? Or does it have to be a URI? – Rudie Sep 1 '14 at 12:29
Wouldn't it have been awesome if the first few people to use that convention years ago had also put nicely concise documentation of their schemas at those URLs so that became a thing? Microsoft's OpenXML namespaces points to nothing. – prototype Sep 23 '15 at 2:46

In general terms, any unique identifier would serve for a namespace; but since it's supposed to be globally unique, the standard would have to either mandate some arbitration authority, or use another resource that is at the same time globally unique but easy to get hold and to prove it's yours.

Oh, look! if you have a domain, it's obviously only yours, and it's easy to prove it's yours!

For example, they wanted to avoid the situation where two different bookstores start using "books" as a namespace, with totally different internal definitions. While they use it internally, there's no problem; but as soon as one of them wants to publish their specification, all hell breaks loose.

Instead, if you're encouraged to use your domain, anybody (well, anybody who owns a domain) can define their own private namespace with the confidence that nobody else will use the exact same identifier.

As a bonus, you can optionally store the definition of your namespace at the URI, making it self-documenting.

Seems like a great idea to me.

share|improve this answer
Thanks for the answer but I would need something more concrete to understand this. I added some exemplar code that you can base on, please take a look. – Patryk Nov 28 '11 at 3:51
@patryk - nothing, it's not an address - it's just a unique token that you are sure no one else that you might mix xml files with has. All it is saying is that the names <table> etc won't be used wit any different meanings in any xml files that have the name at the top – Martin Beckett Nov 28 '11 at 3:59
Ok but when wikipedia says something that users can use for instance as a namespace then a lot of people would have the same namespace. Am I right ? – Patryk Nov 28 '11 at 4:12
@Patryk, only if you want to use it for the same use. If you want to define a new namespace, you're encouraged to use your own domain – Javier Nov 28 '11 at 4:16
@Javier What do you mean by 'the same use' ? – Patryk Nov 28 '11 at 4:39

DOM Level 2 was published in late 2000. It introduced the "getElementById" function as well as an event model and support for XML namespaces and CSS.

What xmlIns specifies?
As attribute nodes named "xmlns" or "xmlns:xxx", exactly as the namespaces are written in the source XML document. This is the model presented by DOM.

What URI contains?
An XML namespace is declared using the reserved XML pseudo-attribute xmlns or xmlns:prefix, the value of which must be a valid namespace name.

For example, the following declaration maps the "xhtml:" prefix to the XHTML namespace:


AS i have discovered after reading the article on Wikipedia. URI contains the XML formatted specifications of the namespace provide a method to avoid element name conflicts.

May be you know xml document uses XML Schema for the element/table/class structure of elements of the XML document.

what should hold ?

The answer is on your page where you have learned about the XML Namespace. Check Namespaces in Real Use section on this W3Schools article.

Check following link of stackoverflow which some what demonstrate that what this URI carries:

How to create and use XML namespace?

share|improve this answer

URI = namespace's globally unique name or identifier

Consider building a database or document on the financial management of the logistics of the oil industry. That would need to use specific vocabularies (i.e., controlled terms) for each of the subjects: database, document, management, finance, logistics, oil, and industry.

If none of the terms overlapped across these seven vocabularies, then only one URI is needed. But for each term that overlaps other terms across these vocabularies, you'd need an additional subject-specific vocabulary identified in a URI or IRI. One way around this is to create a merged taxonomy, with broader general terms and narrower subject-specific terms.

This could then be expanded into a thesaurus that also shows the jargon-synonyms of a term, and enables specification of a preferred term among those jargon-synonyms.

share|improve this answer
this post is rather hard to read (wall of text). Would you mind editing it into a better shape? – gnat Apr 9 at 17:42

protected by gnat Apr 9 at 17:41

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.