News

Simple guide for creating an RSS feed

Posted 23/06/08 by David Web Permalink

Adding an RSS feed to your website or blog is an easy and effective way to keep your visitors up-to-date with your latest news and posts. This quick guide will show you how to write and publish your own feed.

An RSS feed is an XML (eXtensible Markup Language) file that contains a list of your latest news stories in a format that can be easily read by computers and search engines. There is some discussion as to what RSS stands for, but most people opt for "Really Simple Syndication".

To create your own RSS file all you need is a text editor (eg. Notepad) that will let you save files as plain text and also a means with which to upload your new RSS file to your website.

Basic RSS file template

The following sample XML file can be used to create your new RSS feed. Simply create a new file in your text editor, copy and paste the following code and save the file with a suitable name, making sure you save it as a .xml file (eg. myfeed.xml) You can then alter this RSS file to contain details from your own website and news stories.

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Hampton Associates Blog</title>
<link>http://www.hamptonassociates.com/blog</link>
<language>en</language>
<description>Discover the latest news from Hampton Associates and take a sneaky peek at what's going on in the studio...
</description>
<image>
<url>http://www.hamptonassociates.com/media/bloglogo.png</url>
<title>Hampton Associates Logo</title>
<link>http://www.hamptonassociates.com</link>
<width>39</width>
<height>39</height>
</image>
<item>
<title>Blog title number 1</title>
<description>This is a brief description about the blog article and will give visitors an idea of the article before they decide to read it.</description>
<pubDate>Fri, 20 Jun 2008 10:29:28 GMT</pubDate>
<link>http://www.hamptonassociates.com/blog/blog-id</link>
<category>Category title 1</category>
</item>
<item>
<title>Blog title number 2</title>
<description>This is a brief description about the blog article and will give visitors an idea of the article before they decide to read it.</description>
<pubDate>Fri, 20 Jun 2008 10:29:28 GMT</pubDate>
<link>http://www.hamptonassociates.com/blog/blog-id2</link>
<category>Category title 1</category>
<category>Category title 2</category>
</item>
</channel>
</rss>

A breakdown of the RSS file

The basic RSS file as shown in the sample above, consists of three main sections; a header, an image (optional) and a list of items (eg. news stories or blog posts).

The header contains the following -

Title <title>
Title of your RSS feed or website.
Link <link>
The full url that links to your website or news section.
Language <language>
The language that your website and feed are in. A full list of codes is shown on this html language codes table.
Description <description>
A brief description about what your RSS feed is about.

The optional image is used by some RSS programs to help distinguish your feed from others. Try to keep the image dimensions small for best results.

Image Url <url>
The full url of the image.
Title <title>
A suitable title for the image.
Link <link>
The full url that links to your website or news section.
Width <width>
The width (in pixels) of the image.
Height <height>
The height (in pixels) of the image.

Following this you can have a list of items <item> which relate individual news stories or posts. The way these are updated and the amount per RSS feed vary between sites. Some prefer to update their feed with completely new items on a monthly basis while others have a maximum number of items and while new posts are appended to the RSS feed, older posts outwith the max number are removed.

An item contains the following elements -

Title <title>
Title of the post or news article.
Description <description>
A brief description about what the post or article is about.
Publish Date <pubDate>
The date and time at which the item was written.
Link <link>
The full url that permanently links to the article/post on your website.
Categories <category>
Optional list of categories that the item has been assigned to. This can then be used to help filter larger RSS feeds.

Remember to escape special characters

As the RSS file is written in XML you have to make sure that certain characters are in their text form 'escaped', otherwise the XML won't validate and your feed won't work. If you have used any of the following characters when making changes to the sample file then please change them to their 'escaped' variants.

& (change to &amp;)
make sure you change all the & that are included in dynamic urls as these are often overlooked.
" (change to &quot;)
eg. "This is a quote" would become &quot;This is a quote&quot;
' (change to &#39;)
eg. It's almost finished would become It&#39;s almost finished.
> (change to &gt;)
Only change the newly inserted text with these, DO NOT change the actual xml tags, eg. <item> would still remain as <item>
< (change to &lt;)
Only change the newly inserted text with these, DO NOT change the actual xml tags, eg. <item> would still remain as <item>

Upload and validate

Now that you have created your RSS file you need to upload it and insert it into your website. The first step is to upload your .xml file to your website's server using whatever method you normally use (eg. a FTP program).

Once your file is online you should validate it before inserting it into your website. The simplest way to do this is just to enter the full url of your XML file into your web browser and if the feed is loaded without any errors then it has validated successfully.

To insert the feed into your website, all you need to do is include a link to the XML file somewhere on the page. Many websites and blogs now put quite an emphasis on their RSS feeds and prominent links to these are often at the top of the page.

If your website is written using XHTML then you should also include the following line within your <head> tags and change the title and href to your own title and link to the XML file. This will then enable browsers to auto-detect your feed.

<link rel="alternate" type="application/rss+xml" title="Hampton Associates Blog" href="http://www.hamptonassociates.com/feeds/blog.xml" />

Once you upload your updated website files you have finished and have successfully added a RSS feed to your site!