dive into mark

You are here: dive into markArchivesSeptember 2002RSS 2.0 template

Thursday, September 26, 2002

RSS 2.0 template

RSS 2.0 template for Movable Type, ready to copy and paste over your existing RSS 0.91 template (index.xml). No modifications are required, unless your weblog is in a language other than English, in which case you’ll need to change the dc:language tag to your language code. (Use the 2-letter language code, unless there isn’t one for your language, in which case, use the 3-letter language code. And while you’re at it, put the same language code in your HTML tag in your normal page templates. But I digress.)

Here’s what the RSS 2.0 output looks like.

There are several design decisions at work in this template that bear explaining. First of all, this template is designed to be backward-compatible with all existing aggregators, news readers, and RSS parsers, ranging from the super-smart XML parser built into .NET to the dumb, minimal, regular-expression-based parser that your downstairs neighbor banged out on a Friday night. If you upgrade your existing index.xml right now, none of these parsers should crash, and none of your subscribers should scream bloody murder. This is a good thing.

Now then, if you look at the template, you’ll notice a whole slew of lines at the top like xmlns:dc="...". These are namespaces. Keven Hemenway has written an excellent primer on extending RSS 2.0 with namespaces, so I won’t explain them here except to say that we use them, and you should get used to seeing them. Most RSS 2.0 documents you see will use namespaces in some way, because they are the primary way of adding functionality beyond the basic title-link-description combination. If all you want is title-link-description, stick with your existing RSS 0.91 template and stop reading now.

Still here? OK. Now, the RSS 2.0 specification says nothing about how to actually use namespaces in RSS, just that you’re allowed to. So where did these particular namespaces come from? Well, I didn’t make them up. They have been developed over the past two years by some smart people, most of whom hang out on the RSS-DEV mailing list. The namespaces were originally developed for RSS 1.0, and most of them can be used without modification in RSS 2.0. (There’s a lot of stuff I’m skipping over here on purpose. There will be a lot more documentation forthcoming in the next few months on exactly how to use various namespaces in RSS 2.0. Some of it still needs to be worked out, but most of it just needs to be written down. Please be patient.)

So anyway, we use namespaces for a lot of stuff. Most stuff, in fact. In the template, you’ll see title-link-description for channel, and title-link-description-guid for item. guid is new in RSS 2.0, and it is used to uniquely identify an item, so even if the title or description changes, aggregators know that it’s the same item; the end user can choose whether to re-display changed items, but first programs need to be able to track which items are which. (Radio Userland already supports this.) To create the guid, I’ve combined MTEntryID with MTBlogURL to generate a unique string for each item, and I’ve arranged them so there’s no confusion about it possibly being a URL. It’s not a URL; it’s just a unique string. (Other systems have stricter format requirements for guids, but RSS 2.0 does not. A guid is a unique string, and that’s all.)

Pretty much everything beyond title-link-description (and guid) uses namespaces. This template makes use of all 3 of the standard RSS 1.0 namespaces, but there are many other proposed namespaces that have a lot of good design behind them. We use one (admin), which is already widely used; the rest may be useful to you, depending on your niche. (If you think you need to design your own namespace, look through that list and make sure you’re not re-inventing the wheel.)

Back to the template. Other than guid, the most important thing to note about this template is that the title, link, and description are all plain text. (description is an excerpt; if you do not enter an excerpt manually for a post, Movable Type will auto-generate one. You can control how long this auto-generated excerpt is by going to Blog Config, then Preferences, then Number of words in excerpt.) title was always supposed to be plain text, but sticking to plain text in the description tag is an intentional compromise, to support parsers that can not handle HTML, or handle it improperly. Never fear, the full HTML text of your post is still included; it’s stored in the content:encoded element. (Aggie already supports this.) This allows more robust news readers — that can handle either text or HTML — to offer the end user the choice of whether to see excerpts or full posts. Some people use news aggregators to find things to read, others like reading everything directly in their aggregator. RSS 0.9x made you (the author) choose one or the other; RSS 2.0 allows you to offer both, and pass the choice along to the end user. This is a good thing.

There’s more good stuff in there, but the explanations will have to wait for another day. If you’re interested in learning how to extend RSS to suit your needs, your best bet is to read through the documentation of the existing RSS 1.0 namespaces. If you have questions, your best bet is the RSS-DEV mailing list, where Kevin is currently discussing his namespace primer. Archives are public and free, so no subscription is required, and lurking is encouraged.

And watch this space.

Filed under , ,

Respond privately

I am no longer accepting public comments on this post, but you can use this form to contact me privately. (Your message will not be published.)



Recent Stuff For You, Special Price Stay Here
  • Greasemonkey Hacks
Good Stuff Buy The Cow Go Away
Dive Into Python
Powered by Google Drink The Milk Don't Steal

 

posts / comments
© 2001-8 Mark Pilgrim