Building an RSS Feed

How to write an RSS Feed by hand.

Elements of an RSS Feed

There really isn’t a lot of complexity in your basic RSS feed. It’s really simple syndication. Just like with HTML, once you learn the basic elements you’ll be good for 80% of what you want to do, if not more.

XML Declaration

<?xml version="1.0" encoding="UTF-8" ?>

The XML declaration gives applications instructions on how to parse the XML file. The version designates what version of XML to use, and encoding designates what type of encoding is used in the file. It’s unlikely that you’ll need to use different values that what I have here.

<rss>

<rss version="2.0">
  ...
</rss>

This is the root or global element for your RSS file, much like <html> is the root element for an HTML file. The version attribute signifies the version of RSS to be expected in the file. We’re using 2.0 for the reasons previously stated in What is RSS? RSS Versions.

<channel>

<channel>
  ...
</channel>

The channel element is a required child of the rss element. There must be one, and only one channel element in the rss element.

Required Channel Elements

These elements are required to be in your <channel> element.

  • <title>
  • <link>
  • <description>

Your feed won’t work if it’s missing any of them.

Channel <title>

<title>HTML Hobbyist News</title>

The name of the feed. Used very much like the title element in HTML.

<link>https://www.htmlhobbyist.com/</link>

Specifically a URL that links to the website that owns the feed.

Channel <description>

<description>New, updates, and announcements from The HTML Hobbyist.</description>

A summary for the purpose of the feed.

Items

Technically a feed does not require item elements, but what’s the use of having a feed without even one?

The item has the same basic required elements as the channel.

  • <title>
  • <link>
  • <description>

If you have an item element in your feed, it must have these elements in it.

Item <title>

<title>New Section Added: RSS</title>

The title of the item (post, episode, article, etc.) being linked to.

<link>https://www.htmlhobbyist.com/news/rss-section-added/</link>

A URL that points the visitor to the item in question.

Item <description>

<description><![CDATA[ Learn about Really Simple Syndication and making syndicated feeds for your hobbyist site. ]]></description>

A summary or excerpt of the item. This element is only meant to contain a description, summary, or excerpt of the content, and not all of the contents of the linked page. Roughly 200 characters long is suggested. For quick announcements I like to keep the title and description combined to under 120 for potential reuse in short form social media applications. The length is really up to you.

A Simple Feed

The simplest functional RSS 2.0 feed looks something like this:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
              
<channel>
  <title>The Minimum Viable RSS Feed</title>
  <link>https://www.htmlhobbyist.com/</link>
  <description>An RSS Feed that only contains the required elements.</description>

  <item>
    <title>First Item</title>
    <link>https://www.htmlhobbyist.com/news/0001/</link>
    <description>The first item in the simplest RSS 2.0 feed.</description>
  </item>

</channel>
</rss>
simple.xml

Validation

Now that you’ve written the code for your first feed, go and validate it. I won’t remind you again. It’s OK if the validator finds some errors. That’s the entire point. Fix the errors and validate again.

You’ll know you’re done when you see a little badge like this:

[Valid RSS]
A validation badge, for a job well done.

Compatibility

After validating your new feed, you may get a message like this: This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.

For full compatibility you’ll want to do a few more things.

  • Add a guid element to each item element.
  • Add the Atom link element to the channel.

The guid element is a unique identifier that feed readers can use to identify if the user has viewed an item. It usually takes a form that is identical to the link element.

<guid>https://www.htmlhobbyist.com/news/0001/</guid>

The guid element has one attribute, isPermaLink, which if set to true means that the guid must be the permanent link to the webpage associated to that item.

To add the Atom link element, first add the Atom XML namespace to the rss element.

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

Then you can add an atom:link element with a URL that points to the location of your feed into the channel. I place mine near the channel’s link element.

<atom:link href="https://www.htmlhobbyist.com/feed.xml" rel="self" type="application/rss+xml" />

Note that if you paste your feed’s code into the W3C Feed Validation Service Validate by Direct Input tab, you will receive a warning that Self reference doesn't match document location. It’s just a warning.

W3C Feed Validation Service. Congratulations! [Valid RSS] This is a valid RSS feed. Recommendations: This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations. line 8, column 107: Self reference doesn't match document location [help]
A valid feed response on the W3C Feed Validation Service.

As long as you see the “congratulations” message and the badge, your feed is valid. The warning message should go away when you validate by the feed’s URL after it has been uploaded.