Pete Freitag Pete Freitag

Howto Create an RSS 2.0 Feed

Updated on May 26, 2020
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>http://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>http://example.com/item/123</link>
<guid>http://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.



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
hi,
I have some questions, I tried something about rss ut I couldnt have what I want.
I want to have rss same as down simple, with link .
Have can I create it same ?
If somebody can help me I will be very happy.

Thanks.
sorry for my english :(

http://www.etikhaber.com/index2.php?option=com_rss&feed=RSS2.0&no_html=1
by netboard on 11/16/2005 at 10:18:59 PM UTC
hi, thanx for your useful help
i have tow questions :
1. How can I generate rss without this error by validators? :
<i>should not be served with the "text/html" media type</i><br>
this is my rss : http://www.naghsh.net/rss2.0.asp
2. how can i use html in contents of "description" tag?
i don't know how can i use CDATA
by Mehdi on 02/09/2006 at 6:42:22 PM UTC
I am in the process of opening an Yahoo store built with Yahoo Store Editor and even though the web design tools include and "Add On" feature and talk you through putting an RSS feed onto your store site, it doesn't work. I can perform all the directions and cut the html for the news section I want to put on my site, but then the directions become unclear as to WHERE TO PASTE IT! A call to Yahoo tech service said, "Oh, you can't really put an RSS feed on your site with those directions and I don't know how to do it either". Can that possibly be true??
www.alleducationalsoftware.com
by sheryl wood on 03/15/2006 at 7:41:49 AM UTC
I am somewhat new at this. If I create an xml document for the RSS feed with CF variables, it will need to be saved as a .cfm document. How do I define the resulting output to be .xml instead of .html after parsing by the CFServer?
by Tim Cummings on 10/26/2006 at 9:10:10 AM UTC
I'm sorry but your instructions were incomplete. all you have are code snippets, but if someone like me for example, has no idea where to put them, what they are supposed to do, or what to save the file as (xml or cfml) all I get is, nothing from this at all. I need the whole thing coded out from top to bottm, what you are saving each page as, and how exactly do I get the feed to post on my page anyway, I got a link, and so what? how do I make that link post something on my site? It validated very well, but did nothing. I ended up going in circles, I even made and xsl sheet to try and get it to do something, and I got nothing. So whatever. I just need more detailed instructions. You have these code snippets and they are just hanging in the air. Which is probably why so many people have written something to you. It's just too vague. Sorry for the criticism but...I just wasted a half hour of my life for nothing on this. when I "could" be making money.
by Deborah on 12/27/2006 at 6:53:03 AM UTC
Hi,

I'm a newbie to RSS. I am creating a tool to read rss. Is there anyway i can know when a particular rss will get updated or do i have to reload the whole rss again after some time?
by comp on 07/30/2007 at 3:32:01 AM UTC
Thanks for the awesome crash-course in RSS Feeds.
I do have one question: Is there any simple way to have my rss.xml file be automatically updated, or do I have to manually enter each item?
Thanks again!
by Evan S on 09/16/2007 at 8:27:07 AM UTC
Hy, i am new in using and searching more informations about rss,i need to get adviced,regarding a few sites for help and to lern how to update the news.
Thank you!
wiew my e mail adress!!
by oana on 05/12/2008 at 7:43:08 AM UTC
I am using an xsl schema for my RSS feed, if a perticular feed is down. I need to know how to handle it gracefully so I dont show a nasty error message to the user. Is there a way to show a handled/custom error message if a feed is down??
by Sameer Jaffer on 07/17/2008 at 2:38:54 PM UTC
I want to make a new line in only one description tag, but it display whole text in justify form.
So tell me how i can create a new line without creating new description tag.
such like a below.

e.g.
New News. \\Then new Line and print
Another News.
by Dipesh on 07/23/2008 at 6:59:54 AM UTC
so after creating this rss.xml, where should I put it so that the world can get it?
by Mark Thien on 07/31/2008 at 12:24:02 AM UTC
I found this through google and noticed a lot of comments weren't answered. I posted a simple but full code example and some info--based on Pete's helpful overview here-- on my blog:

coldfusionhell.blogspot.com dated 2/22/2009, I don't think the comments will let me paste the whole long link in here but I'll try:

coldfusionhell.blogspot.com/2009/02/coldfusion-cfml-to-make-create-generate.html
by PJ on 02/22/2009 at 8:16:50 AM UTC
I have a years worth of info that needs to be distributed weekly. There is a possibility that some of the info will change in the future but most is set. Is an RSS feed the tool to use or is there a better option?
by Pmousebrown on 08/27/2009 at 8:25:39 PM UTC
Might be worth it to mention - beyond the format, if you want to get the Time in the Standard format - you can use this format: #dateformat(DateConvert('local2utc',now()),'ddd, dd mmm yyyy HH:mm:ss')# GMT
by Kevin Penny on 10/05/2009 at 3:57:25 PM UTC
I had everything working but no images. Wasn't sure about CDATA. Now I got images! Thanks for the info. Nice!
by Duane Charles on 02/06/2010 at 4:26:13 PM UTC