Sunday 05 Jul 2009   
Add Comment

Using CFFEED to create a RSS Feed Tutorial

ColdFusion Tutorial #27

In this tutorial, I show how to retrieve information from a database and create a valid RSS 2.0 feed from this data.

This tutorial should be easily adaptable for your own needs.

demo.cfm

Lines 1-5 just retrieve some data from the cfbookclub sample database.

Lines 7-13 create some required fields for a valid feed.

Line 15 sets up a loop to loop through the data.

Lines 16-24 populate the xml Structure with the data.

I think it is all self explanatory. However lines 18 & 19 define the type of id, a isPermaLink of yes means the guid.value needs to be a permenant link, otherwise it can be a uuid or similar.

Also, remember to xmlFormat and data going into the feed. I have also found that xmlFormat( does not remove high ascii characters, so if you have any of them in your data, you should remove or replace them manually.

 
 


Demo

See this code running!


Download

Download this code as a zip!


Comments

Thanks so much! This was the best DB cffeed example I've found yet....thanks!
Mark @ Wednesday 07 Jan 2009 - 07:34:28 AM

Great tutorial on performing this task. Very helpful.
Ron Kurtus @ Monday 02 Mar 2009 - 10:49:32 AM

Awesome! Thank you
Jimmy @ Wednesday 04 Mar 2009 - 06:29:25 AM

This is the best lesson and example of the CFFeed function I've experienced, even after purusing the web now for 3 months on the subject of incorporating RSS into our web site.
Ross Walker @ Thursday 14 May 2009 - 02:14:42 AM

I would point out that you don't have to convert the query to a structure before passing it to CFFEED. CFFEED can take either a query or a struct. If you use a query, you can create a smaller, simpler columnMap structure to help translate query column to required RSS values.
Raymond Camden @ Monday 01 Jun 2009 - 04:42:06 AM

Click button to add a comment


Author

Dale Fraser


Published

Thursday 24 Jan 2008

Tags

cffeed  cfloop  cfoutput  cfquery  cfset