Practical eCommerce

 

RSS Feeds

Author: Brian Getting
Publish Date: January 31, 2006
Blog: Developers' Corner
Tags: rss, xml

avatar

OK, the RSS feeds are up. There is one for the articles, and another for the podcasts. I thought I would fire out this little tidbit that relates to RSS feeds, but is probably a little advanced to ever make it into the magazine.

So an RSS feed is really just an XML file. The process goes that when you subscribe to an RSS feed using an RSS reader (such as Safari or Vienna), it basically bookmarks the URL where it can find the XML file. It will then check that XML file periodically, compare it to the previous version, and notify you of new articles or content. iTunes Podcasting directory works much the same way, only it will also download the mp3 podcast file when it sees that there is a new one available.

OK, so that being said, the RSS feed does not need to be an actual XML file. In our case, the RSS feeds are PHP scripts that then output in the correct XML format. This is something that most tutorials and such about rss seem to leave out. They always seem to imply that you have to manually go in there and update your feed. Not gonna happen with the magazine, so I opted to have the feeds dynamically generated to ensure that fresh content is pulled from the database.

A couple of things. Ouputting the XML format is a piece of cake, and any PHP developer should have no problem. There is the issue of headers. You may try to validate your RSS feed and see an error that the feed and content-type don't match. Content-Type is a header that is sent by the server describing the content. There are two options for RSS feeds:

I opted for the previous, since it is more universal and also because the seconde option causes some funny things to happen in Firefox. It would assume that based on the content type I wanted to open an RSS reader application and that was annoying. However, the second one has it's place. Check out the head section of our website to see how we use that content type to display the RSS feed in enabled browsers.

Another thing that will prevent validation is if the character encoding sent by the server does not match the character encoding declared in the RSS feed XML file. For example, in our feed I declare that we are using Unicode (UTF-8) encoding:

So I must also ensure that the ouput of my PHP script is encoded this way as well. Both of the above declarations are handled by the PHP header function. As you can see below, it sets the output content type to "text/xml" and the character encoding to UTF-8:

header(’Content-type: text/xml; charset=UTF-8′);

Hopefully this is helpful to anyone that is interested in creating a dynamic RSS feed, but is having trouble getting it to validate.

Add a Bookmark: Add 'RSS Feeds' to Del.icio.us Digg 'RSS Feeds' on Digg.com Submit 'RSS Feeds' to reddit.com Blink 'RSS Feeds' Add 'RSS Feeds' to dzone Seed 'RSS Feeds' on Newsvine Add 'RSS Feeds' to Furl Add 'RSS Feeds' to Spurl Add 'RSS Feeds' on simpy.com Add 'RSS Feeds' to fark.com BlogMark 'RSS Feeds' Add 'RSS Feeds' to Yahoo! myweb2 Add 'RSS Feeds' to wists.com Stumble It!

0 Comments

Sign-up to receive EcommerceNotes, our acclaimed email newsletter.

View A Sample | Privacy

Bloggers Wanted

We’re looking for merchants and other ecommerce professionals to share their experiences with our readers. If this interests you, we invite you to contact us.

Inside Practical eCommerce