Home > Articles > Web Services > XML

RSS 101

  • Print
  • + Share This
Like this article? We recommend

Understanding the RSS specification

The RSS specification is really just a set of instructions that tells you the XML structure that your blog needs to follow in order to be read by RSS-compliant Aggregators. (Another term for a predefined XML structure is an XML schema).

Before we look at the specifics of the RSS specification, let's create a blog that we want to make into an RSS compliant blog feed.

The name of my blog is Bob's Poems.

I will publish two entries in my blog. The first is a poem about roses and violets.

Roses and Violets

Roses are red,

Violets are blue.

The world has a lot,

Of abundance for you.

The second poem is about fresh baked pie.

Fresh Baked Pie

There is nothing,

More enchanting during an afternoon stroll,

Than the smell of fresh baked pie coming from

The kitchen window of a friend.

We'll take this blog, Bob's Poems, and place its entire contents within XML that is RSS-compliant. Then we'll make it so that the resulting XML document can be viewed within an RSS Aggregator as a blog feed.

The RSS specification says that the first thing we need to do is to create a set of XML tags that define our blog feed. In RSS-speak, the stream of XML blog feed data is called a channel. Thus, the specification tells us to start this way:

<rss version="2.0">
<channel>
</channel>
</rss>

Notice that the first line of XML has a begin tag, <rss version="2.0">. The version=2.0 part of the tag is called an attribute, which is an additional way of providing descriptive data in XML. In this case, the attribute, version, has a value of '2.0'. What XML is telling us that that this is XML document uses the RSS specification and that the document supports the 2.0 version of RSS.

The RSS specification requires that we provide three tags within the channel tag: title, link, and description. The title is the name of our blog, the link is a reference URL that might be your home page or a blog-related web page. The description is a short subhead type of entry for our blog. Thus, in terms of my Bob's Poems blog, my title, link, and description tags will look like this:

<rss version="2.0">
<channel>
<title>Bob's Poems</title>
<link>http://www.CogArtTech.com/</link>
<description>Good poems at no cost to the consumer</description>
</channel>
</rss>

These are the only tags that RSS requires you to have within the channel tags. There are other tags, such as <language></language>, <pubDate></pubDate>, and <managingEditor></managingEditor>. These are useful tags, but again they are not required and their absence will not hinder the effectiveness of using RSS to make the blog readable to the Aggregators.

Once we have the channel set up, we need to create items. An item is a distinct blog entry. For example, each of my two poems above can be considered items.

Let's add an item to the RSS-compliant XML document that we are developing. Listing 5 shows the addition of the addition of the <item></item> tags to the RSS channel.

Listing 5: Adding an item to an RSS channel.

<rss version="2.0">
<channel>
<title>Bob's Poems</title>
<link>http://www.CogArtTech.com/</link>
<description>Good poems at no cost to the consumer</description>

<item>

</item>
</channel>
</rss>

The RSS specification requires that an item containing either a title or description tag be included within the <item></item> element. Thus, we'll use the poem's title as our item title.

<rss version="2.0">
<channel>
<title>Bob's Poems</title>
<link>http://www.CogArtTech.com/</link>
<description>Good poems at no cost to the consumer</description>
<item>
<title>Roses and Violets</title>
</item>
</channel>
</rss>

Now we'll add the body of the poem, as shown in Listing 6:

Listing 6: An RSS-compliant XML document with title and description.

<rss version="2.0">
<channel>
<title>Bob's Poems</title>
<link>http://www.CogArtTech.com</link>
<description>Good poems at no cost to the consumer</description>
<item>
<title>Roses and Violets</title>
<description>
Roses are red,
Violets are blue.
The world has a lot,
Of abundance for you.
</description>
</item>
</channel>
</rss>

Amazingly the XML code in Listing 6 can be read in any RSS Aggregator. I'll upload the XML document to my web site and register it with my RSS aggregator. (I'll show you how to register an RSS feed in a RSS Aggregator after we complete the construction of the blog's RSS feed.)

Figure 3 shows you how the uploaded RSS-XML code will be displayed in a typical RSS Aggregator. (In this case I am using FeedReader, a free RSS Aggregator.) Please notice that the poem blog is the last item on the left pane of the RSS Aggregator. Notice also that the title of the particular blog appears in the upper-right pane, and the description of the poem (in this case the poem itself) is displayed in the lower-right pane of the Aggregator's window.

Figure 3

Figure 3 A simple RSS-compliant document displayed in an RSS Aggregator.

How the blog is displayed in the RSS Aggregator is particular to a given RSS Aggregator. One Aggregator might list each registered blog in a horizontal pane. Another might display the blog list in a vertical left pane. Still other RSS feeds can be seamlessly integrated into a web site or portal such as Yahoo or within the browser itself. The important thing to understand here is that as long as your blog feed conforms to the RSS specification, any RSS-compliant reader will be able to handle it. Thus, all you need to worry about is the content of your blog, not the display.

But speaking of display, there is a problem. Please notice that in Figure 3, the line breaks of the poem have been lost.

What should be displayed this way:

Roses are red,

Violets are blue.

The world has a lot,

Of abundance for you.

Is displayed this way:

Roses are red, Violets are blue. The world has a lot, Of abundance for you.

Although it is true that the RSS Aggregator will take care of displaying your content in terms of font color and size as well as page position, you must put code into your RSS description that takes care of line breaks and intended character formatting. Thus, if we want to have the poem appear with line breaks and in italic font no matter what, we will create the XML code shown in Listing 7.

Listing 7: RSS-compliant XML code with character display formatting.

<rss version="2.0">
<channel>
<title>Bob's Poems</title>
<link>http://www.CogArtTech.com/</link>
<description>Good poems at no cost to the consumer</description>
<item>
<title> Roses and Violets</title>

&lt;i&gt;
Roses are red,&lt;br /&gt;
Violets are blue.&lt;br /&gt;
The world has a lot,&lt;br /&gt;
Of abundance for you.&lt;br /&gt;
&lt;/i&gt;

</description>
</item>
</channel>
</rss>

If you think that the code in Listing 7 is a bit weird, you are right. The code in Listing 7 is using a special set of characters to create the tabs for italics and line breaks. These characters are called HTML entities. Table 2 shows the HTML entities used in Listing 7 with the standard character equivalent.

Table 2: HTML entities for tag characters

Entity

Character

&lt;

<

&gt;

>

Thus, the following:

&lt;br /&gt; corresponds to <br />
&lt;i&gt; corresponds to <i>
&lt;/i&gt; corresponds to </i>

The reason we are using these HTML entity characters is so that RSS Aggregator will interpret the line breaks and italic tags as being related only to HTML, not to XML. If the code is considered as XML by the Aggregator, no line breaks or italics will be displayed. It's a peculiar point that will haunt only the very few of us who will be making RSS-compliant code from scratch. Very few of us will be hand-creating RSS-compliant XML. As you become more comfortable with blogging and want to use RSS, you will most likely use some sort of online service that will automatically translate your blog into RSS-compliant feeds.

That being said, let's wrap up and make both poems available as RSS feeds from the Bob's Poems blog. Listing 8 shows the entire XML data for the blog feed for the Bob's Poems blog.

Listing 8: The Bob's Poem's blog as an RSS-compliant XML blog feed.

<rss version="2.0">
<channel>
<title>Bob's Poems</title>
<link>http://www.CogArtTech.com/</link>
<description>Good poems at no cost to the consumer</description>

<item>
<title>Roses and Violets</title>
<description>
&lt;i&gt;
Roses are red,&lt;br /&gt;
Violets are blue.&lt;br /&gt;
The world has a lot,&lt;br /&gt;
Of abundance for you.&lt;br /&gt;
&lt;/i&gt;
</description>
</item>

<item>
<title>Fresh Baked Pie</title>
<description>
&lt;i&gt;
There is nothing,&lt;br /&gt;
More enchanting during an afternoon stroll,&lt;br /&gt;
Than the smell of fresh baked pie coming from&lt;br /&gt;
The kitchen window of a friend.&lt;br /&gt;
&lt;/i&gt;
</description>
</item>

</channel>
</rss>

Figure 4 shows the XML code from Listing 8 displayed in an RSS Aggregator.

Figure 4

Figure 4An RSS Aggregator displaying multiple blogs.

  • + Share This
  • 🔖 Save To Your Account