RSS 2.0 - The Simplest Possible RSS 2.0 Feed
(Page 4 of 4 )
This, really, is the key to the success of RSS 2.0. The simplest thing you need to do to make the feed validate is very uncomplicated indeed (see Example 4-2). While this isn't any help when you are trying to convey complex information, as with RSS 1.0, or if you're trying to build a complete document-centric system, as with Atom, it is very useful for many other applications.
Example 4-2. The simplest possible RSS 2.0 feed
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>The Simplest Feed</title> <link>http://example.org/index.html</link> <description>The Simplest Possible RSS 2.0 Feed</description>
<item>
<description>Simple Simple Simple</description>
</item>
</channel>
</rss>
Chapter 10 describes many useful applications that take this a minimalist approach to using RSS 2.0--compliant feeds.
Producing RSS 2.0 with Blogging Tools The vast majority of RSS 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 personal use at http://www.movabletype.org. In order to discuss a few important implementation points, Example 4-3 shows a template for Movable Type that produces an RSS 2.0 feed.
Example 4-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>ben@benhammersley.com </managingEditor> <webMaster>ben@benhammersley.com</webMaster> <docs>http://blogs.law.harvard.edu/tech/ 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 are worth close examination. 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 822--for 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 these are all present because some desktop readers and aggregators aren't as forgiving as others, and many are getting less so as they develop.
Implementation of the guid element is equally important. The RSS 2.0 standard doesn't 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 you have to formulate your own system. (I'll touch upon this again when we talk about Atom in Chapter 7.)
For the template shown earlier, 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 isn't reflected in the link to the entry, the link alone isn't a good guid. So, by combining the link with the last-updated-date value, I can 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 URL--which, of course, it isn't. Hence:
<guid isPermaLink="false">GUID:<$MTEntryLink$> </g<$MTEntryDate format=
"%a%d%b%Y%I:%M"$></guid>
This works well as an RSS 2.0 guid, but it has one feature that might annoy: because weblog comments cause the guid to change, it also causes the item to be marked as unread in many feed aggregators. This might not be desirable behavior for you.
Please check back next week for the continuation of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter four of the book Developing Feeds with RSS and Atom, written by Ben Hammersley (O'Reilly; ISBN: 0596008813). Check it out today at your favorite bookstore. Buy this book now.
|
|