RSS 2.0 is still too young for any dedicated programmatic tools to have appeared, so the vast majority of 2.0 feeds are produced by weblogging tools that use templates. The most popular of these is Movable Type, written by Ben and Mena Trott, which is freely available for for noncommercial use at http://www.movabletype.org. In order to discuss a few important implementation points, we will now look at a template for Movable Type, shown in Example 8-3, that produces an RSS 2.0 feed.
Example 8-3. A Movable Type template for producing RSS 2.0
<?xml version="1.0"?> <rss version="2.0"> <channel> <title><$MTBlogName$></title> <link><$MTBlogURL$></link> <description><$MTBlogDescription$></description> <language>en-gb</language> <copyright>All content Public Domain</copyright> <managingEditor>email@example.com</managingEditor> <webMaster>firstname.lastname@example.org</webMaster> <docs>http://backend.userland.com/rss</docs> <category domain="http://www.dmoz.org">Reference/Libraries/Library_and_Information_Science/ Technical_Services/Cataloguing/Metadata/RDF/Applications/RSS/</category> <generator>Movable Type/2.5</generator> <lastBuildDate><$MTDate format="%a, %d %b %Y %I:%M:00 GMT"$></lastBuildDate> <ttl>60</ttl> <MTEntries lastn="15"> <item> <title><$MTEntryTitle encode_html="1"$></title> <description><$MTEntryExcerpt encode_html="1"$></description> <link><$MTEntryLink$></link> <comments><$MTEntryLink$></comments> <author><$MTEntryAuthorEmail$></author> <pubDate><$MTEntryDate format="%a, %d %b %Y %I:%M:00 GMT"$></pubDate> <guid isPermaLink="false">GUID:<$MTEntryLink$></g<$MTEntryDate format="%a%d%b%Y%I:%M"$></guid> </item> </MTEntries> </channel> </rss>
The vast majority of this template is standard Movable Type fare. Taken from one of my own blogs , it uses the <$MT$> tags to insert information directly from the Movable Type database into the feed. So far, so simple.
Two things need to be noted. First, the date format:
<pubDate><$MTEntryDate format="%a, %d %b %Y %I:%M:00 GMT"$></pubDate>
Care must be taken to ensure that the format of the contents of the date fields are correctly formed . RSS 2.0 feeds require their dates to be written to comply with RFC 822for example: Mon, 03 Jan 2002 0:00:01 GMT .
Common errors found in RSS 2.0 feeds include missing commas, seconds values, and time zones. You must ensure that these are all present, as some desktop readers and aggregators are not as forgiving as others.
Implementation of the guid element is equally important. The RSS 2.0 standard does not discuss the form of the guid . It only asks the author to ensure that it is globally unique. There is no scope for the OSF GUID standard to be used within most blogging tools, so we have to formulate our own system.
For the template shown in Example 8-3 I considered various things. First, the guid 's purpose is to tell applications if the entry is new or if it has changed. Second, within my own blogs I allow people to add comments to the entries. I consider this a change to the entry, so my guid must reflect this. Because this change is not reflected in the link to the entry, the link alone is not a good guid . So, by combining the link with the last-updated-date value, I am able to make a guid that is globally unique and changes when it needs to. For added measure, I add the string GUID to the front of it to prevent it from looking too much like a retrievable URLwhich, of course, it isn't. Hence:
<guid isPermaLink="false">GUID:<$MTEntryLink$></g<$MTEntryDate format="%a%d%b%Y%I:%M"$></guid>
Now that we know how to make RSS feeds in all the latest formats, let's move on to Chapter 9.