1. Computing

Discuss in my forum

Anatomy of an RSS File

How to Build an RSS File from Scratch

By

A Sample RSS Feed

A Sample RSS Feed

Image courtesy J Kyrnin

RSS or Really Simple Syndication is a very easy XML language to learn because there are only a few tags that are required. And what's really great about RSS is that once you've got a feed up and running, it can be used all over the place. Most Web browsers can read RSS, as well as readers like Google Reader and Bloglines. RSS is a powerful tool for any Web developers who want to increase the visibility of their Web sites.

Tools Required to Write RSS

  • A text editor
    You can use almost any editor that will generate plain ASCII text. I prefer to use jEdit because it's free and it checks the XML for me as I write. But you can also use HTML editors like Dreamweaver or BBEdit.
  • An RSS validator
    If you use an XML editor like jEdit, an RSS validator isn't absolutely required. But I find that errors creep in even in the best editors, so validating the feed is always a good idea.

A Simple RSS 2.0 Document

This RSS 2.0 document has one item in the feed along with the feed information. This is the minimum you need to have a valid and usable RSS feed.

<?xml version="1.0" encoding="utf-8"?>
 <rss version="2.0">
 <channel>
 <title>A Sample RSS 2.0 Feed</title>
 <link>http://webdesign.about.com/rss2.0feed/</link>
 <description>An example of a simple RSS feed. This is the description of the feed itself, not an item.</description>
 
 <item>
 <title>This is the most recent entry in my sample feed</title>
 <link>http://webdesign.about.com/rss2.0feed/entry.html</link>
 <description>This is the text that will appear in the feedreaders. It describes the post itself, not the entire feed.</description>
 <guid>http://webdesign.about.com/rss2.0feed/entry.html</guid>
 </item>
 
 </channel>
 </rss>

As you can see, a basic RSS document has very little required to create a fully functional feed. If you were to paste that code into an RSS validator, it would validate - which means that RSS feed readers could read it too.

The first three lines tell the user agent that this is an XML document, it's an RSS 2.0 file, and there is a channel:

<?xml version="1.0" encoding="utf-8"?>
 <rss version="2.0">
 <channel>

The version information isn't required, but I find that it's a good idea to include that attribute on the <rss> tag.

Every feed should have a title, URL, and description. And that's what the <title>, <link>, and <description> tags that live within the channel (but not within an <item>) define. For most feeds, these elements will never change once you've decided on your feed name and description.

<title>A Sample RSS 2.0 Feed</title>
 <link>http://webdesign.about.com/rss2.0feed/</link>
 <description>An example of a simple RSS feed. This is the description of the feed itself, not an item.</description>

The last part of the feed are the items themselves. These are the stories that will be syndicated by your feed. Each item is enclosed in an <item> element.

<item>

Inside the item you find the same three tags we already know: <title>, <link>, and <description>. They perform the same function as they do outside the item tag, but inside they reference just that one item. So the text inside the <description> is what displays in the feed reader, the title is the title of the post, and the link is where the post links to.

<title>This is the most recent entry in my sample feed</title>
 <link>http://webdesign.about.com/rss2.0feed/entry.html</link>
 <description>This is the text that will appear in the feedreaders. It describes the post itself, not the entire feed.</description>

The only new tag is the <guid> tag. This element tells the user agent or feed reader what the unique URL is for that post. This can be the same URL as the link or a separate permanent link (permalink) for the item.

<guid>http://webdesign.about.com/rss2.0feed/entry.html</guid>

The only thing remaining is to close the item, the channel, and the rss. Because this is XML, all tags need to be closed.

</item>
 </channel>
 </rss>

Add New Items to the Top

Most RSS feeds consist of more than one item at a time. This way, if a customer is new to your site, they can see the last few posts, or all of them, if you keep them all in the RSS. To add a new post, just add a new item above the first post:

...
 <item>
 <title>A second post</title>
 <link>http://webdesign.about.com/rss2.0feed/entry2.html</link>
 <description>Now my feed has 2 posts</description>
 <guid>http://webdesign.about.com/rss2.0feed/entry2.html</guid>
 </item>
 <item>
 ...

Additional Elements to Dress Up Your RSS Feed

The above RSS is all you need to create a feed, but there are a lot of optional tags that can help improve your feed and provide additional information to your readers. The following are some of my favorite optional tags that you can use to improve your RSS Feeds.

  • <language> - use this tag to tell the reader what language your feed is in. You can use standard language codes, or the language-country designation with country codes added on (like en-us for U.S. English).
  • <copyright> - the copyright notice for your channel.
  • <managingEditor> - the email address of the person responsible for the feed's content.
  • <image> - an image of your feed's logo. This tag includes the sub-tags: <url>, <title>, <link>, <width>, and <height>.

Note, that the image <link> must match the channel <link> and the image dimensions cannot be larger than 144 pixels wide and 400 pixels tall.

All of the above tags go in the <channel> and describe the feed, rather than individual items, like this:

...
 <channel>
 <title>A Sample RSS 2.0 Feed</title>
 <link>http://webdesign.about.com/rss2.0feed/</link>
 <description>An example of a simple RSS feed. This is the description of the feed itself, not an item.</description>
 <language>en-us</language>
 <copyright>Copyright 2007, Jennifer Kyrnin</copyright>
 <managingEditor>webdesign@aboutguide.com (Jennifer Kyrnin)</managingEditor>
 <image>
 <title>About.com</title>
 <url>http://0.tqn.com/f/lg/s11.gif</url>
 <link>http://webdesign.about.com/rss2.0feed/</link>
 <width>144</width>
 <height>25</height>
 </image>
 ...

Now you can build your own RSS feed.

  1. About.com
  2. Computing
  3. Web Design / HTML
  4. XML
  5. Specifications
  6. RSS
  7. Anatomy of an RSS File - How to Build an RSS File from Scratch

©2014 About.com. All rights reserved.