RSS and the Web Introduction
UT graphic
Introduction to RSS and the World Wide Web                                  



RSS Examples

RSS feeds can be created within a simple text editor or dynamically generated by a program. To access RSS feeds you can have programs that output the feeds within your web page.


Creating a simple RSS feed

The <?xml version="1.0"?> tag is the first line of your RSS file. This is the first line of any RSS file. Regardless of standard you decide to use.

<?xml version="1.0"?>

The next line specifies what version of RSS you are using. In our example we are using RSS 2.0.

<?xml version="1.0">
<rss version="2.0">
</rss>

The next line is the 'channel' tag.

<?xml version="1.0"?>
<rss version="2.0">
<channel>
</channel>

</rss>

Next we will add the required <channel> elements. These must be in your RSS file.

<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title> ITC News and Announcements </title>
<link> http://itc.utk.edu/ </link>
<description> The latest news from itc.utk.edu, the Innovative Technologies Center web site. </description>

</channel>
</rss>

Now we place our item elements. This element is the heart of the RSS feed. It contains the primary content. item elements are optional but an RSS feed without any items is nothing more than a regular link.

<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title> ITC News and Announcements </title>
<link> http://itc.utk.edu/ </link>
<description> The latest news from itc.utk.edu, the Innovative Technologies Center web site. </description>
<item>
 <title> CMS 110 Introduction </title>
 <link> https://itc.utk.edu/workshops/workshoplist.shtml#cms110 </link>
 <description> CMS 110 Intro to Online@UT workshop - Wed, Sept 8, 1:30-3:30 </description>
</item>
<item>
 <title> Call for Proposals </title>
 <link> http://edtech.tennessee.edu/modules/set2005/2005_cfp.shtml </link>
 <description> ETC's 2005 Project SET Call for Proposals - due Sept. 13, 2004 </description>
</item>

</channel>
</rss>

http://bmw.ws.utk.edu/xml/rss/examples/example1/example1.xml

or

RSS icons graphic


Adding a few useful tags

The above example is a simple RSS file that could be classified as RSS 0.91, 0.92 or 2.0. In other words it is a "bare bones" example. that is frequently good enough to suit your purposes. As RSS has evolved, more tags have been added as options. Below we will add a few to our example.

Here we add language, copyright, lastBuildDate, and category tags for channel and items.

<language> en-us <language> - allows parser to only look for english, spanish, etc RSS items
<lastBuildDate> Tue, 19 Oct 2004 04:00:00 GMT </lastBuildDate> - last time the content of the channel changed
<category> biology </category> - at channel level specifies one or more categories the channel belongs to
<category> botany </category> - at item level specifies one or more categories the item belongs to

<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title> ITC News and Announcements </title>
<link> http://itc.utk.edu/ </link>
<description> The latest news from itc.utk.edu, the Innovative Technologies Center web site. </description>
<language> en-us </language>
<copyright> Copyright 2004 Innovative Technologies Center </copyright>
<lastBuildDate> Tue, 19 Oct 2004 04:00:00 GMT </lastBuildDate>

 <category> biology </category>
<item>
 <title> CMS 110 Introduction </title>
 <link> https://itc.utk.edu/workshops/workshoplist.shtml#cms110 </link>
 <description> CMS 110 Intro to Online@UT workshop - Wed, Sept 8, 1:30-3:30 </description>
 <category> microbiology </category>
</item>
<item>
 <title> Call for Proposals </title>
 <link> http://edtech.tennessee.edu/modules/set2005/2005_cfp.shtml </link>
 <description> ETC's 2005 Project SET Call for Proposals - due Sept. 13, 2004 </description>
 <category> botany </category>
</item>
</channel>
</rss>

http://bmw.ws.utk.edu/xml/rss/examples/example2/example2.xml

or

RSS icons graphic

Source code of how to use image has a hot link


Using a Feed Validator

Once you have made your RSS feed you may want to submit it to a validator to to make sure you do not have any errors that will not be acceptable to parsers.

Below is one example of an RSS feed validator

http://feedvalidator.org


Directories

You may want to create a central directory for your organization if you have several RSS feeds from dirrerent departments.

You can submit your RSS feed to various RSS feed directories. Below are a couple.

http://www.syndic8.com
http://www.newsisfree.com - must create an account in order to add feeds
http://www.rssfeeds.com


A Simple Parser

To read an RSS feed you need to parse the file. You can then include it in your web page. Here we will parse the first RSS feed example above with a sample PHP script.

newsparse.php

newsparse.php source code


Create our own feeds

  1. Open "notepad" and cut and paste the source code above in the first example. (Or do the equivalent on your unix account with desired editor)
  2. Edit the file with your own headlines
  3. upload or save the file to your unix account in your "public_html" directory. If you do not have the directory create it by typing: mkdir public_html


Make our own simple parser

Now lets set up a simple RSS parser on your account.

  1. cut and paste the source code of the newsparse.php to your public_html directory
  2. edit the line "$lib=new NewsList('../example1/example1.xml');" and put the URL of the RSS feed you want to parse. For example: $lib=new NewsList('http://rssfeeds.webmd.com/rss/rss.aspx?RSSSource=RSS_PUBLIC');
  3. open the newsparse.php file in your web browser. For example: http://web.utk.edu/~jbrose/newsparse.php


Using parsing application within a web page

Lets look at parsing with magpieRSS, a PHP parsing application.

Lets look at the class feeds using magpieRSS, a popular PHP RSS parser application.

Single web page with our class RSS feeds - using magpieRSS

default.php source code

magpieRSS source code


Cron jobs can parse an RSS feed and create server-side include file

It may not be neccessary to access the RSS feed every single time your web page loads. You can set up a cron job to access the RSS feed at a regularly scheduled time and create an include file for youe web page.

server-side include example
news.shtml - the server-side include file inserted automatically into page above
PERL program executed by cron - creates the above server-side include by parsing the RSS feed across the network
cron file example - file to set time for RSS feed to be parsed and include file to be created


RSS Feed to Javascript tool

You can provide a feed to this tool, then it will create the javascript that you can cut and paste into your website.

RSS to Javascript


Other RSS Examples

Simple PHP Blog creates RSS/Atom feeds automatically of posts
Simple PHP Blog

MSN search results in RSS format

Moving on . . .





For questions or comments
Email: jbrose@utk.edu     Phone: (865) 974-1009
web: http://www.cs.utk.edu/~rose

July 23, 2008, 5:49 pm