Extending RSS 2.0 With Namespaces

With the recent release of RSS 2.0 by Userland, there's been a healthy amount of discussion over the smallest part of the spec: Extending RSS. This document attempts to clarify that section, by discussing the creation of the blogChannel Module from Dave Winer, and the underlying principles of namespaces.

This document is not intended to be the "end-all, be-all" of namespace discussions. For the sake of simplicity, I've left a lot of things out and I'm not talking in all the "right technical terms". If you have a healthy knowledge of namespaces already, you'll probably find something to nitpick about, and that's ok... this document is not definitive but rather an end-level, low-tech bundle of joy.

This is a work-in-progress. Email morbus@disobey.com concerning modifications, thoughts, etc.

Table Of Contents

  1. What is a Namespace?
  2. The blogChannel Module
  3. Do's and Don't's
  4. Nitpicks
  5. Credits
  6. Version History

What is a Namespace?

Without getting overly complicated, a namespace is like a toy chest. "You can buy as many toys as you want", your Mother says, "but at the Do not make me beat you, son. end of the day, be sure to put them away". You know your Mother has a reason for saying this, because you've seen your Father fall a few times, thus breaking your new toys. The loss of time, money, and back pain mowing lawns is not a pleasant one.

In RSS (and its parent technology, XML), a namespace ensures that your toys won't be tripping up your father's feet. To bring this out of metaphor land and into reality, namespaces allow you to create any new element you desire, without causing problems with other elements.

Let's show a simple example. In the document below, I've randomly decided to include a <banking> element for each of my <item>'s. In this case, I'm saying "I'd like to add a new element called <banking>, which tells the name of the bank I'm using" (yeah, it's a piss-poor example, but it'll make sense in a second):

 <item>
  <title>A simple example</title>
  <description>A simple example</description>
  <banking>Bank of Montreal</banking>
 </item>

Now, this is all fine and dandy until you think about the world around you. Take a look at this example, created by some smarmy guy in Washington who wanted to add his own elements, just like you:

 <item>
  <title>A simple example</title>
  <description>A simple example</description>
  <banking>Turn the rudder 45 degrees to the left.</banking>
 </item>

It's obvious that his definition of <banking> (how a plane moves through the air) is different than your definition of <banking> (what bank you place transactions at). This is an example of "breaking your father's back" - since you didn't put your toys in your toy chest, problems are occurring. How are your readers supposed to know which <banking> is being talked about? Airplanes or financials? That's where namespaces come in.

Here's an example of another <item> only with namespaces added:

 <item>
  <title>A simple example</title>
  <description>A simple example</description>
  <airplanes:banking>Turn the rudder 45 degrees to the left.</airplanes:banking>
  <financial:banking>Bank of Montreal</financial:banking>
 </item>

Do you see what we've done here? We've preceded each <banking> element with another name and a colon (:). When you create a namespace, you choose an arbitrary prefix (like "airplanes" or "financial"), throw on a colon (ending up with "airplanes:" and "financial:" and add your element name ("banking", which creates the examples shown above).

Huh. Bam-Bam must really weight a lot. Fatso. The benefit for a piece of software is immediate: it now knows that one sort of banking is different than another sort of banking. There was no way it could tell this without namespaces. Note that I've used meaningful names above, but you don't have to - you could easily have used <blah:banking> and <flintstones:banking>. To software, the difference would still be relevant, but it merely makes things more confusing for human readers of your RSS feed.

Just choosing a namespace prefix isn't all, though. You also have to choose a namespace URL [nitpick], one that you have control over, and which will never change. We'll see where this comes in later, but for now, I'm going to say that the URL for the "financial" namespace is http://www.example.com/financial# and the URL for the "airplanes" namespace is http://www.foobar.com/ns/airplanes/. Generically speaking, you want to end your URL with either # or / [nitpick]. The reasons why are multifold, but just trust us on this one. These URLs don't have to resolve to any document (but it's good practice to have a document explaining more about the elements).

The blogChannel Module

The first module available for RSS 2.0 was blogChannel created by Dave Winer. It's a rather simple addition that brings three new elements to your RSS 2.0 feed, blogRoll, mySubscriptions, and blink. These new elements are child elements of the normal <channel> element that has existed within RSS since day one. You can see them in use here and as a quick sample below:

 <rss version="2.0"
     xmlns="http://backend.userland.com/rss2"
     xmlns:blogChannel="http://backend.userland.com/blogChannelModule">
 <channel>
  <title>Scripting News</title>
  <link>http://www.scripting.com/</link>
  <blogChannel:blogRoll>http://radio.weblogs.com/ ... /file.opml</blogChannel:blogRoll>
  <blogChannel:mySubscriptions>http://ra ... /file.opml</blogChannel:mySubscriptions>
  <blogChannel:blink>http://inessential.com/</blogChannel:blink>
  .
  .
  .
 </channel>
 </rss>

Let's note a couple of things:

With the above in mind, let's add our fictional <banking> elements:

 <rss version="2.0"
     xmlns="http://backend.userland.com/rss2"
     xmlns:blogChannel="http://backend.userland.com/blogChannelModule"
     xmlns:financial="http://www.example.com/financial#"
     xmlns:airplanes="http://www.foobar.com/ns/airplanes/">
 <channel>
  <title>Scripting News</title>
  <link>http://www.scripting.com/</link>
  <blogChannel:blogRoll>http://radio.weblogs.com/ ... /file.opml</blogChannel:blogRoll>
  <blogChannel:mySubscriptions>http://ra ... /file.opml</blogChannel:mySubscriptions>
  <blogChannel:blink>http://inessential.com/</blogChannel:blink>
  .
  .
  .
   <item>
    <title>A simple example</title>
    <description>A simple example</description>
    <airplanes:banking>Turn the rudder 45 degrees to the left.</airplanes:banking>
    <financial:banking>Bank of Montreal</financial:banking>
   </item>
  .
  .
  .
 </channel>
 </rss>

Here, we've added our namespace declarations to <rss>, continued on with the same <blogChannel> examples as before, but also added an <item> which includes our two <banking> elements. These elements both contain the different namespace prefixes we declared in <rss>. And that, as they say, is that. For aggregators and software that understand our new elements, they'll be golden - for those that don't, our new elements will be silently ignored.

Do's and Don't's

Have other do's or do not's? Email morbus@disobey.com.

Nitpicks

Have other complaints? Email morbus@disobey.com.

Credits

Thanks to Ken MacLeod, Sean Palmer, Phil Ringnalda, and Aaron Swartz for early and crucial comments concerning this document. You all forced me to include the Nitpicks section because you're crazy ninjas. Visual Credits: 1. Some innocent family's baptism photos, 2. A 1979 tin bank of Pebbles and Bamm Bamm - it was manufactured as part of a set that all bear the words "Bedrock Bank Unbreakable" on the sides, 3. What happens when you type "woot" into Google's image search, 4. Self-explanatory.

Version History

Morbus Iff (aka Kevin Hemenway), 2002-09