"To live in regret is to tie yourself to the past; to live in hope is to open your future." - Anonymous

Writing An Atom Feed

Sunday 23rd October 2005

Categories: Guides, Internet, Code

Finishing Touches

We are nearly there now! Firstly, we need to close the feed. We do this simply by adding this at the end of the XML file:

</feed>

Note that for each part of the feed, I haven't listed all the possible elements - you can find a fuller list using the Atom specification.

Now we need to add the feed to the website. We can do this in two ways. The first is to embed it in the pages of the websites. In the head of your pages, add this line:

<link rel="alternate" type="application/atom+xml" title="The Title Of Your Feed" href="atom.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. You should be able to find a multitude of appropriate icons using the image search on Google. 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 Atom 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 Atom file. The (X)HTML code might look like this:

<a href="rss.xml"><img src="images/atom.png" alt="Atom 1.0 Feed" title="Atom 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.

Useful Links