Simple Web Syndication with RSS 2.0 - The XML:RSS 2.0 namespace
(Page 3 of 6 )
Let’s begin with the basics. You’ll start your RSS feed by setting up an XML document.
<?xml version="1.0" ?>
<rss version="2.0">
<channel>
The opening tag establishes our file as an XML document. The next tag tells the XML parser that we are using the RSS 2.0 namespace. This allows us to use “short” tag names to reference our elements. Finally, we use the channel element to indicate the start of our RSS channel feed.
Next we want to identify what our channel will hold. In this example, I’m going to build an RSS feed for all of my articles published on the Developer Shed network of sites. So I’ll add this next piece of code.
<title>Popular Articles by Nilpo</title>
<description>Popular articles by Nilpo published by Developer
Shed.</description>
<link>http://www.nilpo.com</link>
<language>en-us</language>
The first three elements are required. The title element defines the name of your channel. In most cases this is just the name of your web site. The description provides a brief overview of the channels contents. The link element is used to provide a valid URI to the html website that the channel corresponds to. I’ve also included the language element. This element optionally defines the language that the channel is written in. Valid values for this element must be RFC 1766 compliant.
Now that we’ve established a channel, we can begin adding content. The RSS 2.0 namespace provides the item element for this. Take a look at the following code segment.
<item>
<title>A New Toolbar Can Boost Your Web Site Traffic
Dramatically</title>
<description>Dev Articles - Embedded Tools - 1/10/07</description>
<link>http://www.devarticles.com/c/a/Embedded-Tools/A-New-Toolbar-Can-
Boost-Your-Web-Site-Traffic-Dramatically</link>
</item>
Here we’ve defined at item for our channel. Three basic elements are required: title, description, and link. Title defines the title for our item. This should be a descriptive name for the content that it holds. In my case, the name of the article is appropriate. The description should describe the content. I could have given and overview or an introduction to the articles, but instead I chose to add the site information and publication date. Finally, the link element should provide the URL to the content itself.
You would add subsequent items in the same way. Each item should be enclosed it its own item element.
</channel>
</rss>
We end our RSS channel by closing the channel and rss tags. This is a basic RSS feed although at this point it’s still formed pretty poorly. Many news readers would have a hard time updating this feed properly because we haven’t provided any information to differentiate between existing items and newly added ones.
Next: Expanding the channel >>
More XML Articles
More By Nilpo/Developer Shed Staff Writer