Creating RSS feeds
The root element
The first element in an RSS document is the root rss
element.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
</rss>
The channel element
The next required element is the channel element.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
</channel>
</rss>
Within each RSS feed the channel document must have the following elements: title, link, description. These elements are used to give a title to the feed (name of the channel), a link to the website where the feed comes from and a description of the feed.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Pixelcode news</title>
<link>http://pixelcode.co.uk</link>
<description>Pixelcode news articles.</description>
</channel>
</rss>
Optional channel elements
The following are optional channel elements.
Element | Description |
---|---|
language | The language of the feed. Values can be found at the RSS website. |
copyright | A copyright notice for the channel. |
pubDate | The date of the latest addition in this format. |
lastBuildDate | The date that the channel was last changed in this format. |
managingEditor | Email address of the editor of the feed. |
webMaster | Email address of the web master relating to the feed. |
generator | Name of the program used to make the feed. |
docs | A link to the RSS home page. |
ttl | Time to live, specifies the number of minutes before the feed is refreshed. |
image | An image to be displayed alongside your feed. |
More optional channel elements.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Pixelcode news</title>
<link>http://pixelcode.co.uk</link>
<description>Pixelcode news articles.</description>
<language>en</language>
<copyright>Pixelcode 2008</copyright>
<pubDate>Mon, 6 Oct 2008 12:00:00 GMT</pubDate>
<lastBuildDate>Mon, 6 Oct 2008 12:00:00 GMT</lastBuildDate>
<managingEditor>editor@myfeed.co.uk</managingEditor>
<webMaster>webmaster@myfeed.co.uk</webMaster>
<generator>MyGenerator v2.0</generator>
<docs>http://www.rssboard.org/rss-specification</docs>
<ttl>60</ttl>
<image>
<url>http://pixelcode.co.uk/feed.png</url>
<title>Pixelcode news feed</title>
<link>http://pixelcode.co.uk</link>
<!-- the values below are the maximum values for width and height -->
<width>144</width>
<height>400</height>
</image>
</channel>
</rss>
The item element
Item elements are where the data are stored. They must contain either a title or description.
Element | Description |
---|---|
title | A title of the item. |
link | Link to the relevant URL. |
description | Description of the current document. |
author | Author of the current item. |
comments | Link to a page that contains comments about the feed. |
guid | A string unique to that feed. |
pubDate | Date when the item was published in this format. |
source | The RSS feed that the item relates to. |
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Pixelcode news</title>
<link>http://pixelcode.co.uk</link>
<description>Pixelcode news articles.</description>
<language>en</language>
<copyright>Pixelcode 2008</copyright>
<pubDate>Mon, 6 Oct 2008 12:00:00 GMT</pubDate>
<lastBuildDate>Mon, 6 Oct 2008 12:00:00 GMT</lastBuildDate>
<managingEditor>editor@myfeed.co.uk</managingEditor>
<webMaster>webmaster@myfeed.co.uk</webMaster>
<generator>MyGenerator v2.0</generator>
<docs>http://www.rssboard.org/rss-specification</docs>
<ttl>60</ttl>
<image>
<url>http://pixelcode.co.uk/feed.png</url>
<title>Pixelcode news feed</title>
<link>http://pixelcode.co.uk</link>
<!-- the values below are the maximum values for width and height -->
<width>144</width>
<height>400</height>
</image>
<item>
<title>News item 1</title>
<link>http://pixelcode.co.uk</link>
<description>Description of item 1.</description>
<author>Pixelcode</author>
<comments>http://pixelcode.co.uk/comments/1/</comments>
<guid>http://pixelcode.co.uk/news/1/</guid>
<pubdate>Mon, 6 Oct 2008 12:00:00 GMT</pubdate>
<source url="http://pixelcode.co.uk/feed.rss">Pixelcode news</source>
</item>
</channel>
</rss>