Creating an RSS 2.0 Feed
If you can learn HTML, you can easily learn how to build your own RSS 2.0 feeds. I’ll take you through the steps to creating an RSS feed from scratch.
Step 1: XML Declaration
Since RSS 2.0 must validate as XML, the first line in your rss feed must be the XML declaration.
<?xml version="1.0" encoding="utf-8"?>
The encoding is optional but recommended. If your using something other than UTF-8 be sure to change the above line.
Note: If you are using CFML and have whitespace due to the Application.cfm file you can reset the output buffer using <cfcontent reset=”true”>
Step 2: RSS Channel
In this step we need to open up the
rss tag, and the
channel tag, all of your feed content goes inside these tags.
Step 3: RSS Feed Information
Next you place information about your RSS feed such as the title of it, the description, and a link to the the site.
<title>The title of my RSS 2.0 Feed</title>
<description>This is my rss 2 feed description</description>
<lastBuildDate>Mon, 12 Sep 2005 18:37:00 GMT</lastBuildDate>
lastBuildDate should be the date and time that the feed was last changed. Dates in RSS feeds should comply to RFC 822. In CFML the DateFormat mask would be
ddd, dd mmm yyyy and the TimeFormat would be
HH:mm:ss. Dates should be offset to GMT. The
lastBuildDate tag is not required but is highly recommended.
Step 4: RSS Items
Next we enumerate over each RSS item, each item has a title, link, and description, publication date, and guid.
<title>Title of an item</title>
<pubDate>Mon, 12 Sep 2005 18:37:00 GMT</pubDate>
<description>[CDATA[ This is the description. ]]</description>
<!-- put more items here -->
Make sure you escape any characters that might cause your XML to invalidate, these characters include <, >, & – I like to enclose any content that may contain HTML inside a CDATA section.
Note: In CFML you can use the XmlFormat function to escape special characters in XML.
Step 5: Close Channel and RSS tags.
Step 6: Validate your feed
Validate your feed using FeedValidator.org.
Other things to take note of
- Content Type – See my post on content types for RSS feeds
- Encoding – You should include the encoding in your
Content-TypeHTTP header, and in the XML declaration.
- Styling – If you want to make your RSS feed look a little nicer you can CSS stylesheet for your RSS feed.
- Categories – It’s a good idea to include
categorytags in your RSS feeds as well, these go inside the
itemtag. You can give an item multiple categories by adding a tag for each one.
I have just scratched the surface of what you can do with RSS feeds, so check out the RSS 2.0 Spec for more info.
Do you digg it?
- Apple still likes their RSS icon – January 10, 2006
- Zookoda For Sale – September 22, 2006
- Simple Flex Tutorial – November 7, 2005
- SoloSub is for button addicts – October 6, 2005
- Google Sitemaps Accepts RSS and Atom Feeds – September 12, 2005
Pete Freitag (http://www.petefreitag.com/) is a software engineer, and
web developer located in central new york. Pete specializes in the
HTTP protocol, web services, xml, java, and coldfusion. In 2003 Pete
published the ColdFusion MX Developers Cookbook with SAMs Publishing.
Pete owns a Firm called Foundeo (http://foundeo.com/) that specializes
in Web Consulting, and Products for Web Developers.