Howto Create an RSS 2.0 Feed
By Pete Freitag
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 theitem
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.
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:
- Foundeo's 2007 End of the Year Sale
- Apple still likes their RSS icon
- 9 Ways to Save Bandwidth on your RSS Feed
- Yahoo Pipes Generates Invalid RSS Feeds
Discuss / Follow me on Twitter ↯
Tweet Follow @pfreitagComments
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.
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.
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-
...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.
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.
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.
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
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
www.alleducationalsoftware.com
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?
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!
Thank you!
wiew my e mail adress!!
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.
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
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.