Skip Navigation LinksHome > View Post

Use URNs not URLs in your namespaces when they do not point anywhere

It's just good manners. And that concludes this post.

Just kidding - I'm going to bore you with why I'm saying this, so lets meet the family...

First, there's URI (Uniform Resource Identifier), he's the daddy. Then there's the two brothers, URN (Uniform Resource Name) and URL (Uniform Resource Locator).

URN

A URN is part of the URI family (that is, it *is* a URI) that simply identifies a resource but doesn't indicate or point to the availability of said resource. Which is true because when I paste this 'urn:www.agxml.org:schemas:all:2:0' in to my browser's address bar it doesn't take me anywhere. It's just a token that identifies something and makes it unique.

URL

A URL is also part of the URI family. Similarly, a URL also serves to identify a resource and is also a unique token. But a URL also 'provides means of acting upon or obtaining a representation of the resource by describing its primary access mechanism or network "location".'. Which is true because when I stick this 'http://www.thejoyofcode.com/ it does lead somewhere (our homepage).

So?

Next time you're creating the schema for your latest and greatest Xml based messaging doodah and start writing namespace="http:/..., think!

Is the namespace actually going to point to something? Maybe I'll point it to the .xsd that describes the schema at my website or maybe I'll point it to some documentation that describes the schema. In which case go for a URL. Otherwise, if like most of us it's just some nonsense you made up (e.g. http://www.thejoyofcode.com/schemas/aloadofnonsenseimadeup), then go for a URN.

Still with the URL? Bear this in mind - changing the namespace of an XML document/schema is a breaking change. So if the location of your said documentation is likely to change - you might still want to go for a URN.

Some tips

When inventing URNs (what fun!) I tend to follow this pattern...

    urn:schemas-thejoyofcode-com:application-or-system-name:sub-system-or-component-if-appropriate:2007-01

Were the date at the end is the month and year that the schema was first created. Anyway, be sure to check out the excellent references at wikipedia listed below.

References

Tags: ASP.NET

 
Josh Post By Josh Twist
8:32 AM
29 Jan 2007

» Next Post: Most compelling example of WPF to date
« Previous Post: Open Containing Folder

Comments are closed for this post.

Posted by Mark Mc Keown @ 27 Feb 2007 7:18 AM
If you choose to use a URN as a namespace, then you cannot provide a representation of the resource that it identifies later. Why restrict yourself? For the purposes of identification a http URI is just as good as a URN.

Also, http URIs are NOT locations.

See W3C tag document on this issue, http://www.w3.org/2001/tag/doc/URNsAndRegistries-50.html

© 2005 - 2014 Josh Twist - All Rights Reserved.