The whole point of namespaces is that they provide a means of establishing unique identifiers for elements and attributes. It is therefore imperative that each and every namespace have a unique name. Obviously, there would be no way to enforce this rule if everyone was allowed to make up their own names out of thin air, so a clever naming scheme was established that tied namespaces to URIs (Uniform Resource Identifiers). URIs usually reference physical resources on the Internet and are guaranteed to be unique. So, a namespace is essentially the name of a URI. For example, my web site is located at http://www.michaelmorrison.com. To help guarantee name uniqueness in any XML documents that I create, I could associate the documents with my namespace: <mediacollection xmlns:mov="http://www.michaelmorrison.com/ns/movies"> The ns in the namespace name http://www.michaelmorrison.com/ns/movies stands for "namespace" and is often used in URL namespace names. It isn't a necessity but it's not a bad idea in terms of being able to quickly identify namespaces. If you don't want to use a URI as the basis for a namespace name, you could also use the URN (Universal Resource Name) of a web resource to guarantee uniqueness. URNs are slightly different from URLs and define a unique location-independent name for a resource that maps to one or more URLs. Following is an example of using a URN to specify a namespace for my web site: <mediacollection xmlns:mov="urn:michaelmorrison.com:ns:movies">
Keep in mind that a namespace doesn't actually point to a physical resource, even if its URI does. In other words, the only reason namespaces are named after URIs is because URIs are guaranteed to be uniquethey could just as easily be named after social security numbers. This means that within a domain name you can create URIs that don't actually reference physical resources. So, although there may not be a directory named pets on my web server, I can still use a URI named http://www.michaelmorrison.com/ns/pets to name a namespace. The significance is that the michaelmorrison.com domain name is mine and is therefore guaranteed to be unique. This is important because it allows you to organize XML documents based upon their respective namespaces while guaranteeing uniqueness among the namespace names. |