Writing An RSS Feed
Friday 9th September 2005
Categories: Guides, Internet, Code
Finishing Touches
We are nearly done now. Once you have added all of the items in the feed, you need to close the channel and RSS feed. You do this by adding:
</channel>
</rss>
The result should be similar to what was displayed a few pages ago. Now, we need to add the feed to the website. We can do this in two ways. The first is embed it in the pages of the websites. In the head of your pages, add this line:
<link rel="alternate" type="application/rss+xml" title="The Title Of Your Feed" href="rss.xml" />
Obviously, the title attibute should be the title of the feed, while the href attribute should point to the feed itself. This feed allows programs such as Opera and Mozilla Firefox to find the feeds. We can also add the feed as a button. First of all, you will need to find an appropiate button for your web page. A quick search on Google shows a multitude of images you could use. When you do use an image, make sure that you upload to your own webspace, and that it is not copyrighted. Common ones to use are the orange buttons with XML and RSS written on them, although, for the sake of continuity, this site has a different button.
Next, put the button on your page, and create a link to the RSS file. The (X)HTML code might look like this:
<a href="rss.xml"><img src="images/rss.png" alt="RSS2.0 Feed" title="RSS Feed" height="15" width="80" /></a>
If you're using HTML, rather than XHTML, you won't need the forward slash at the end of the <img>
tag. The various attributes, especially the link, image source and dimensions, will obviously need changing to the correct values.
And that should be it! Users of your site should now be able to find and view and your feed. If the feed doesn't work, make sure you have all the right tags, with correct spelling and cases (as in upper and lower cases), and that each tag is closed correctly.