The primary purpose of namespaces is to resolve ambiguity. An XML document can contain more than one element with the same name, but each of them may have different meaning. For example, an XHTML document may have a <table> element which refers to an HTML table. But it can also have a <table> element which refers to a wooden table.
Similarly, think of an XML document which uses the element <provider> for an Internet Provider as well as for a Database connection provider. When an XML parser finds such an ambiguous element, it needs to understand in which context the element has to be interpreted. This is when a namespace declaration can come at help. By adding a namespace prefix to the element, we can resolve ambiguity. With the addition of a namespace the elements will become <html:table> and <furniture:table>. Similarly <provider> becomes <Internet:provider> and <database:provider>.
I am pretty sure that most of you out there, must have came across cases where you need to resolve some kind of ambiguity. If you are a database developer you must be using table aliases to avoid ambiguity when two tables are joined. If you are a .NET developer you must be putting your classes into different namespaces so that "Database.Connection" object is differentiated from "Internet.Connection", where "Database" and "Internet" stand as namespaces. Each programming language has its own syntax which the developer should follow to avoid ambiguity while accessing objects or variables.
Namespaces were added to XML for the same purpose. With the help of a namespace, an XML document can be extended. You can add additional information to your XML documents without breaking the validation rules. With the advent of Web 2.0, RSS and ATOM feeds have become a "must have" in every Web Site. There are specifications which strictly controls the structure of the XML. An RSS feed will be considered valid only if it follows the structure defined by the specification. This means that the structure of an XML document is very rigid most of the times. Though we call it 'eXtensible Markup Language' (XML), we cant simply go ahead and extend it by adding our own elements. If I add '<PhoneNumber>' to an RSS document, this will break the specification rules the feed will be considered as invalid. Almost all feed parsers and readers will reject my RSS feed because it contains an element that is not permitted.
So how do I 'eXtend' my XML document? Why do you call it 'eXtensible'? Well, we can extend an XML document by using a namespace. I can declare a namespace which points to my own information and can add '<my:PhoneNumber>' and it will not break the specification defined for the given XML document. So we could say that, with the help of a namespace, one can add additional information to an XML document. The additional information will not disturb parsers which expects the previous XML structure. Those parsers will not even see the new information. The new information will be seen by only parsers which will specifically look for the additional namespace. This will make our XML documents 'eXtensible'.
We have seen many of the XML features exposed by SQL Server 2005. We had seen how to generate XML results using FOR XML keyword in the early sessions of XML Workshop. Chapter 10 of XML Workshop explains the usage of namespaces. This session shows an example which generates an XML Result Set having namespace information with TSQL.