/beyond/webmaster/article.php/3864491/Really-Simple-Syndication-A-Web-Developers-Class-on-RSS.htm Really Simple Syndication: A Web Developer's Class on RSS

Really Simple Syndication: A Web Developer's Class on RSS

By David Fiedler

Now that we have blogs, Twitter and live content on the web, it's critical for sites to have fresh content available for their visitors. This class on RSS will show developers how they can have "real time" content on their sites with just a few lines of JavaScript.

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
In the static days of Web 1.0, web pages were created individually by hand, and updates were relatively few and far between. Unless you ran a busy news site or portal, your basic content rarely changed. Now sites are expected to have the latest, breaking news and content, everything changes all the time, so it's critical for everyone to know what the newest content is.

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 Feed

When 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:

  • Title--The title of your site WebDeveloper.com
  • Link--The URL of your site http://www.WebDeveloper.com
  • Description--Short description of your site WebDeveloper.com, Where Web Developers and Designers Learn How to Build Web Sites, Program in HTML, Java and JavaScript and More!

    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:

    <?xml version="1.0"?>
    <rss version="2.0">
    <description>WebDeveloper.com, Where Web Developers and Designers Learn How to Build Web Sites, Program in HTML, Java and JavaScript and More!</description>
    Most feeds have a bit more information, and here's what's usually also included at minimum for the channel:
    <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:
    <title>Simple Syndication</title>
    <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>
    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
    must always go at the very end of the file. If you want to check your work, submit its URL at FeedValidator.org.

    Reading an RSS Feed

    Importing an RSS feed from another site is technically easy. JavaScript is the classic method because it's easy to copy, paste, and modify, but using it means that search engines won't pick up the included content. On the other hand, it's not really your page's content in the first place, so that shouldn't be of major concern.

    There is the matter of following the Terms of Use for the other site's feed. The mere availability of an RSS feed doesn't automatically entitle you to use all its content in any way you like on your own site. You may be limited to a certain number of articles, where you can place them (for example, in a sidebar only), how many words you can use from each article, and so on. Even without these legal restrictions, you would be well advised to think in terms of layout when you display feeds from other sites. You would hate to see your own content and links pushed off the page because you didn't constrain the size and typeface of the feed, for instance.

    With all that in mind, some popular sources for JavaScript services include Feed2JS, RSS2HTML, Grazr, and Google's Dynamic Feed Control Wizard (OK, that's technically Ajax). Depending on someone else's server for this is not so much to worry about, since you're depending on someone else's server for your feed anyway! Just make sure that the code, no matter what kind you're using, is surrounded by some sort of HTML container ( <P>, <TABLE>, <IFRAME> ) so the content doesn't "leak" out onto the page, and you'll be set!

    Here's an example of how it could look on your page, using Feed2JS and the RSS feed from HTMLGoodies: