Really Simple Syndication: A Web Developer's Class on RSS
RSS (Really Simple Syndication) provides a mechanism for website owners to do two basic things:
- Advertise their newest content, so that people can find and read it (using news/feed readers or by embedding it in their own sites)
- Embed advertised RSS content from other sites in their own
If your site is run by a popular blog or CMS (Content Management System) package such as WordPress, Blogger, or Joomla, then you don't even have to worry about this, because your software already provides handy, fully-integrated, click-and-you're-done methods of importing and exporting RSS feeds.
However, you may have a static site, or are creating a site of your own design (using a database or not). The easiest method is to use a free web-based service (such as Page2RSS or RSSA or Feed43) that regularly checks or "scrapes" your pages for changes, then publishes the changes as an RSS feed. Nothing to it, really, except you're now dependent on their server and service. If, like most developers, you prefer to run things yourself, you'd need to know the basics of creating a basic RSS feed. Fortunately, that's not too difficult.
How-To: Writing an RSS FeedWhen you're dealing with standards, the first best place to go is to the specifications. Luckily the RSS specs are well-defined and reasonably small. In fact, if you read carefully, you'll see there are only three elements required for a "legal" RSS feed, although in practice you'll want a few more. At a bare minimum at the top level, you need:
This is all fairly simple and straightforward, but there's just one more thing. An RSS feed is written in XML, so it needs a bit of structure. The final, net-ready version would look something like this, which simply describes a "channel", or the website itself:
<language>en-us</language> <lastBuildDate>Tue, 9 Feb 2010 18:47:00 GMT</lastBuildDate>And finally, most feeds also have one or more items to describe each new individual article on the page or site. These are structured much like the top-level channel, but remember they must describe the articles themselves. I recommend the following as a minimum:
<item> <title>Simple Syndication</title> <link>http://www.WebDeveloper.com/syndication.html</link> <description>A tutorial on how to import and export RSS feeds to and from your website.</description> <pubDate>Tue, 9 Feb 2010 18:00:00 GMT</pubDate> <guid>http://www.WebDeveloper.com/syndication.html</guid> </item>With this repeating format, it's relatively simple to generate a valid RSS feed from your database as long as you're outputting HTML. Please note that the lines
</channel> </rss>must always go at the very end of the file. If you want to check your work, submit its URL at FeedValidator.org.
Here's an example of how it could look on your page, using Feed2JS and the RSS feed from HTMLGoodies: