Creating an RSS feed : The Channel

Author: John Fowler

Let's go back to RSS. Now that we know that RSS is written in XML, and how XML works we can take a look at what an actual RSS feed looks like:

<channel>
    Channel information
    Items
</channel>


The channel information and items also comprise of XML elements. Notice how the entire data about the feed is stored within description tags, each named 'channel'. This should not come as a surprise as we mentioned already that RSS feeds are also referred to as RSS Channels amongst a few other names.

Let's take a look at the channel information first. The following is a fictional news feed from a site that provides news stories from around the milky-way galaxy.

<channel>
    <title>Galactic News</title>
    <link>http://www.galacticnews.scf/rss/ </link>
    <description>Galctic news delivers up-to-the-minute news and information on the latest top stories, in
    the Milky Way galaxy</description>

    Item 1
    Item 2
    …

</channel>


Let's take a closer look at the elements:

We have the title element used for naming the feed. The link element contains the location of the feed's XML file. And finally, the description element which describes the feed.

Those 3 elements are mandatory and can't be left out. In addition there are a few more elements that are optional. Let's take a look at a few of the more useful ones:

Language – this tag specifies the language in which the feed in written.

Copyright – this tag informs of the person or organization holding the copyrights of the channel's contents.

Pubdate – this tag specifies the publication date for the channel's contents. It must be in written in RFC 822 format as demonstrated in the following example: Wed, 14 Jan 2004 11:17:12 GMT.

Ttl – Time To live. The maximal period of time (specified in minutes) during which the channel can be cached. Once that period is over the feed must be read again. This is actually a pretty important and useful element, as you would want RSS readers and aggregators to read your feeds the least amount of times necessary. Reading the feed consumes bandwidth, and as feeds tend to contain pretty large multimedia elements nowadays this feature is becoming increasingly important .We shall discuss multimedia elements in greater detail later on.

Let us now incorporate those additional elements into our feed:

<channel>
    <title>Galactic News</title>
    <link>http://www.galacticnews.scf/rss/</link>
    <description>Galctic news delivers up-to-the-minute news and information on the
    latest top stories, in the Milky Way galaxy</description>
    <language>en-us</language>
    <copyright>© 2004 MW News Network inc.</copyright>
    <pubDate>Wed, 14 Jan 2004 11:17:12 GST</pubDate>
    <ttl>5</ttl>

    Item 1
    Item 2
    …
</channel>


Image is another optional element. Using this element we can place an image next to the feed's title. We chose to separate the image element example from the other optional elements as it contains sub elements within it and we wanted to move forward one step at a time.

<image>
    <title>" "</title>
    <width>" "</width><height>" "</height>
    <link>" "</link>
    <url>" "</url>
</image>

The use of the title, link and description elements has already been clerified. You should match the values entered to those of the channel as they represent the exact same thing. The url element specifies the location of the image displayed. There are also the width and height elements that much like in HTML are optional. Those specify the width and height of the image in pixels. The image itself must be formatted as either GIF, JPEG or PNG.

Let's add the image element to our galactic news feed example:

<channel>
    <title>Galactic News</title>
    <link>http://www.galacticnews.scf/rss/</link>
    <description>Galactic news delivers up-to-the-minute news and information on
    the latest top stories in the Milky Way galaxy</description>
    <language>en-us</language>
    <copyright>© 2004 MW News Network inc.</copyright>
    <pubDate>Wed, 14 Jan 2004 11:17:12 GST</pubDate>
    <ttl>5</ttl>
    <image>
       <title>Galactic News</title>
       <link>http://www.galacticnews.scf/rss/</link>
       <url> http://www.galacticnews.scf/rss/galactic-news-logo.png</url>
       <width>100</width>
       <height>40</height>
       <description>Galactic news delivers up-to-the-minute news and information on the
       latest top stories in the Milky Way galaxy</description>
    </image>

    Item 1
    Item 2
    …
</channel>

For a complete list of all optional elements check this page:

http://blogs.law.harvard.edu/tech/rss

2006 © Society for Technological Education | Site Map | Contact Us