Pete Freitag Pete Freitag

Howto Create an RSS 2.0 Feed

Updated on May 28, 2025
By Pete Freitag
web

If you can learn HTML, you can easily learn how to build your own RSS 2.0 feeds. I'll take you through the steps to creating an RSS feed from scratch.

Step 1: XML Declaration

Since RSS 2.0 must validate as XML, the first line in your rss feed must be the XML declaration.

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

The encoding is optional but recommended. If your using something other than UTF-8 be sure to change the above line.

Note: If you are using CFML and have whitespace due to the Application.cfm file you can reset the output buffer using <cfcontent reset="true">

Step 2: RSS Channel

In this step we need to open up the rss tag, and the channel tag, all of your feed content goes inside these tags.

<rss version="2.0">
<channel>

Step 3: RSS Feed Information

Next you place information about your RSS feed such as the title of it, the description, and a link to the the site.

<title>The title of my RSS 2.0 Feed</title>
<link>https://www.example.com/</link>
<description>This is my rss 2 feed description</description>
<lastBuildDate>Mon, 12 Sep 2005 18:37:00 GMT</lastBuildDate>
<language>en-us</language>

The lastBuildDate should be the date and time that the feed was last changed. Dates in RSS feeds should comply to RFC 822. In CFML the DateFormat mask would be ddd, dd mmm yyyy and the TimeFormat would be HH:mm:ss. Dates should be offset to GMT. The lastBuildDate tag is not required but is highly recommended.

Step 4: RSS Items

Next we enumerate over each RSS item, each item has a title, link, and description, publication date, and guid.

<item>
<title>Title of an item</title>
<link>https://example.com/item/123</link>
<guid>https://example.com/item/123</guid>
<pubDate>Mon, 12 Sep 2005 18:37:00 GMT</pubDate>
<description>[CDATA[ This is the description. ]]</description>
</item>
<!-- put more items here -->

Make sure you escape any characters that might cause your XML to invalidate, these characters include <, >, & - I like to enclose any content that may contain HTML inside a CDATA section.

Note: In CFML you can use the XmlFormat function to escape special characters in XML.

Step 5: Close Channel and RSS tags.

</channel>
</rss>

Step 6: Validate your feed

Validate your feed using FeedValidator.org.

Other things to take note of

  • Content Type - See my post on content types for RSS feeds
  • Encoding - You should include the encoding in your Content-Type HTTP header, and in the XML declaration.
  • Styling - If you want to make your RSS feed look a little nicer you can CSS stylesheet for your RSS feed.
  • Categories - It's a good idea to include category tags in your RSS feeds as well, these go inside the item tag. You can give an item multiple categories by adding a tag for each one.

I have just scratched the surface of what you can do with RSS feeds, so check out the RSS 2.0 Spec for more info.

You can create all kinds of RSS feeds, I have another service that I use to create a RSS feed for CVEs and security vulnerabilities, which is quite handy.



rss xml feeds howto

Howto Create an RSS 2.0 Feed was first published on September 13, 2005.

If you like reading about rss, xml, feeds, or howto then you might also like:

Discuss / Follow me on Twitter ↯

Comments

Thanks for this great information as always. Your CF Cookbook is an awesome resource as well.

I assume the answer to the following question is "yes" but figured I'd ask anyway before delving in, as you will likely know the answer off the top of your head.

You alluded to this in your posting... is it possible to evaluate cfml variables inside of the RSS <item> tags?

For instance:
<item>
<title><cfouptput>#feed1title#</cfoutput></title>
<link><cfouptput>#feed1link#</cfoutput></link>
<guid><cfouptput>#feed1guid#</cfoutput></guid>
<pubDate><cfouptput>#feed1pubDate#</cfoutput></pubDate>
<description><![CDATA[ This is the description. ]]></description>
</item>

Thanks again for helping with the understanding of this powerful capability.
by Mark H. on 09/14/2005 at 12:14:04 AM UTC
Also handy is to place the following tag in the headsection of your RSS <ttl>60</ttl> This wil make sure that an RSS reader does not read your feed more then 1 time every 60 minutes. (feeddemon etc...)
by Tjarko on 09/14/2005 at 3:02:28 AM UTC
Hi Mark,

Thanks!

Yes you can generate an RSS feed with CFML variables just like you would a HTML page with CFML. So suppose you have a db table with company news. If you wanted to create a RSS feed for that you would do a <cfoutput query="news"> <item> ...</item></cfoutput> One thing to keep in mind is that all the content inside the tags needs to be XML save, so you either want to use CDATA or XmlFormat or both.
by Pete Freitag on 09/14/2005 at 9:24:23 AM UTC
Tjarko,

Yes the TTL feature is very handy, I omitted it from this example because I didn't want to overload people with details. Also handy is the skipDays, skipHours tags, if your a business and you only update the content on weekdays you can tell readers to take the weekend off.
by Pete Freitag on 09/14/2005 at 9:27:05 AM UTC
Pete,
Many thanks for the reply and great info. I am working on getting my first feed up and running in the next 5 weeks (among other work) and this is a great head-start/ encouraging questions.
Thanks and cheers-
by Mark Holton on 09/14/2005 at 7:19:00 PM UTC
Thanks. I was looking for something like this recently
by Sudar on 09/16/2005 at 4:23:50 AM UTC
Thanks for these links, Bill.
...easier to use these services, well, maybe in the short term. It depends on what you want to do with RSS, what your goals are. Understanding the technology and how to create feeds makes it "easier" to leverage in your site(s), through automation, etc. Thanks again, Pete, for the great references. Looking forward to the next post.
by Mark Holton on 09/16/2005 at 7:38:00 PM UTC
George,

I think that depends on the reader - most of them will store a copy locally. So once you publish something to your RSS feed, you can remove it but some people will still get it - it's kind of like sending an email.
by Pete Freitag on 10/04/2005 at 11:22:06 AM UTC
Jamesy, most rss readers will grab your feed every hour. You can use the ttl tag to specify a time to live for your feed, they will obey that if it is set higher than one hour, and some readers may grab it more often if it is set below an hour.
by Pete Freitag on 10/17/2005 at 8:51:01 AM UTC
Jamsey,

Yes, you can specify skip days, and skip hours in your rss feed as well, aggregators should not download your feed on a skip day or skip hour. See: http://blogs.law.harvard.edu/tech/skipHoursDays for details.
by Pete Freitag on 10/17/2005 at 9:19:33 AM UTC