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
can you enter the structure of your table?
thanks
ken @ Friday 02 Oct 2009 - 03:29:04 AM
This is a quick and easy tutorial. Thanks. It really helped me out with creating my feed.
Just one note on this, because in my application, I have a lot of codes running before reaching the point of creating the script, therefore I have to add in this line before the final cfoutput tag:
<cfcontent type="text/xml" reset="yes">
And it has to sit right before it without ny extra space otherwise the feed wont be validated.
Here is my final 2 lines:
<cffeed action="create"... >
<cfcontent type="text/xml" reset="yes"><cfoutput>#trim(myXML)#</cfoutput>
If you see your script display PLAIN XML or sometimes even PLAIN TEXT, try to add in that line.
Cheers,
Khoa
Khoa @ Saturday 05 Dec 2009 - 11:56:41 AM
Click button to add a comment
Author
Dale Fraser