An RSS 2.0 Crash Course

I saw our first 'non-iMarcian' comment yesterday, and it was asking about RSS. Not only have I never really built anything RSS related, I've never even looked into using it. Sounding like a fun challenge, at 6:30pm on Sunday I made my first Google search and within an hour and a half, I had an RSS feed for our blog ready to go.

Since things were so simple, I thought I'd share how I went about building things to maybe help those that are interested in it.

The first thing I looked up was "What is RSS" in Google. This returned a couple of good articles, mainly the full explanation from everyone's favorite encyclopedia (except China), Wikipedia. RSS stands for "Really Simple Syndication" and is used to port fresh content from a Website to an aggregator. Cool.

Next, I needed to find out the specifications for RSS. This returned a Harvard Law Website, which at first seemed weird but hey, if you can't trust Harvard Law these days, who can you trust?

It turns out that this page would be all that I'd really need.

Not only did this site provided the basic explanation for RSS again, but also gave sample files right off to get a feel for what I was going to build. I love it when tutorials do that, because I'd rather see what I'll be creating, and then have each piece explained to me. In fact, I'm sure you could get everything you want from that page, so I'll just use this as a general overview of steps and the 'gotchas' I came across along the way.

Note, this is geared towards making an RSS feed for your blog, but you can easily incorporate this information into make an RSS feed for anything.

The first thing to decide on is what standard you want to adhere to. I chose 2.0, mainly because it seemed the most recent, and is what all of the cool tech sites (or mainly digg.com) use.

To start your feed, declare your XML intentions and then open an rss tag, and inside of that, start a channel tag:
<?xml version="1.0" encoding="utf-8"?>
You'll see that the RSS version is defined within the rss tag. A channel is just another name for your feed.

Before loading items, we have to create a title and description for our RSS feed. This will be used by aggregators to determine where the feed came from and what it's about. We do this by adding some tags not inside an item tag. This is what we used:
Communiqué iMarc's blog en-us Copyright 2005, iMarc LLC http://www.imarc.net/communique
These should be pretty self-explanatory. A couple of notes: title, description and link are all required, the rest were just added as options. More options include managingEditor, webMaster, pubDate, lastBuildDate, category, generator, docs, cloud, ttl (time to live), image, rating (based on PICS), textInput, skipHours and skipMinutes. Again, no need in re-inventing the wheel, read all about it here.

Now that we have our channel defined (which again, is just your feed), we need to add items. Each item you add will be one entry displayed in your feed. Simple enough.

Items use a lot of the same tags as channel, and just using the basics are pretty much good enough. Here is a sample item based on the tags that we used:
Blog Title This is a sample description of my blog entry. Sun, 23 Oct 2005 20:05:12 EDT /communique/view/1/blog_title /communique/view/1/blog_title#comments /communique/view/1/blog_title
You'll notice a couple of new tags here. First, the pubDate tag. This date must "conform to the Date and Time Specification of RFC 822, with the exception that the year may be expressed with two characters or four characters (four preferred)." If you are looking to do this with PHP's date() function, use this:
<?php echo date("D, d M Y H:i:s T"); ?>
Also, guid (which stands for globally unique identifier) is used by aggregators to determine if a feed has new entries or not. Think of this as the primary key in MySQL. Further research said that there is no required syntax for this, but from what I find there are a couple of standards that you should try and follow:
Use Your Website
Start your guid with your website, that way you never accidentally copy over another feed from another site.

Use a Link that Links to Your Site/Entry
Opera seems to use the guid as the link to the item you're talking about instead of the actual link tag. I'm not sure why, but just a heads up.
The comments tag is the URL users can type in to read or leave comments about each item.

You can add as many of these item tags as you'd like. When you're done adding items, all you have to is close your channel and rss tags, like so:
Save your file as a ".xml" file and there you have it: your very first RSS feed.

It's a good idea to validate your feed once you have it created. I used FeedValidator.org to accomplish this, as they give you a very simple interface with clear error messaging.

I found there were a couple of common errors that kept getting returned. Since our blog is called "Communiqué", the é kept causing problems (in fact not just in the RSS feed, but around the site too, for links and such). You should use HTML entities when creating characters like this, but in this case, I took a different road. To convert our titles into nice search engine friendly ones, we created a PHP function that takes a string of text (which would be your title in most cases), strips out the weird characters, converts spaces to underscores, and converts accented characters to non-accented versions of the same character. While this may seem like a bad practice, we took into account a couple of key thoughts:
  1. Most people won't confuse a word without accents with a word with the appropriate accents when it's used in context.
  2. A blog is about communication, and communication is information travelling from one person to another person intact. Without these accents, the message will still get through correctly 99.9% of the time.
  3. Building off #2, well, you can't please all of the people all of the time.
To get this page to be dynamic, I built a PHP script to create this feed, and set up cron to hit the feed-creator page every twenty minutes. This is probably overkill for us for now, but the amount of resources it takes is minimal enough that it isn't a problem. The page simply builds up a feed into one long string and then writes that string out to our feed XML page. Easy, and everything works correctly.

Finally (yes, finally), the concept of live bookmarking. We all use Mozilla's Firefox aroundFigure 1: Live Bookmark Icon the office here, and with this browser comes the option of live bookmarking. This allows you to subscribe to a feed as a bookmark, and it automatically refreshes throughout the day. (If you're on Firefox, down at the bottom of your screen there should be a small orange icon in the status bar. Click that.) At first I was perplexed as to how to get this to appear, but found the solution. It all happens in your page's head tag:
The title is what will pop up when a user clicks on the orange icon, and it's used to tell which feed they're subscribing too. This is good if you have multiple feeds on one page. The href points to your RSS feed (just like you'd create an HTML link). You can have as many of these tags as you want, and each will list separately in the list of options in which users can subscribe.

And there you have it, an RSS crash course. I went from just knowing of this technology to having a decent handle on it in about ninety minutes, and its application seems greatly useful all over the place (and all thanks to the user comment my last entry received). Hope this helps, and if you have any tips of your own, please add them in a comment below.

Comments

Tuesday, Oct 25, 2005 / 9:34am Will Bond said…

So, according to your three item bulleted list, you concluded to remove the accented character, however it seems the RSS feed still includes the accented e?

Do RSS readers handle html entities properly (I thought that XML did not always play well with html entities)?

Comments have been turned off on this blog.
Read something more recent.

Statements and opinions expressed in this blog and any comments made are the private opinions of the respective poster, and, as such, iMarc LLC is neither responsible nor liable for such content.

Meet The Author

(Fred)

Fred LeBlanc

iMarc Alumnus

Search

Recent Blog Posts

Recent Comments

  • Changes

    Jean Fitzgerald commented: Congratulations Jeff! It's a great move for you, the company will never regret it. You are one of the most creative people I know too.

  • Changes

    Claire Turcotte commented: Jeffrey! Congratulations. VERY PROUD OF YOU. Send me an answer............ Love, Memere

  • What To Know Before You SEO

    seo course bangalore commented: Wow, awesome blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is fantastic, as well as the content! http://seocoursevideo.com/worry/

  • Changes

    Nick Hill commented: Congrats to Will and Jeff!

  • Scrolling, clicking, and the fold

    jay commented: Yeah ,,people will scroll up and down no matter what, now a days a lot of sites have horizontal scroll ..Personally i think scrolling is better than clicking..no time to waste lookin for the link and then clicking..scrolling offers all in one go.

We heart Visitors

  • iMarc
  • 14 Inn Street
  • Newburyport, MA 01950
  • Phone: (978) 462-8848
  • Fax: (978) 462-8807
  • Directions

Contact Us

Whether you have a huge project or just want to talk about updating your site, we’re here to help. Fill out the form, and we’ll get right back to you.

Contact Us
  • All Fields Required

Close