ColdFusion tutorial to export from database to RSS

Always wanted to export items from your existing database into RSS with ColdFusion and syndicate it, but don’t know how?

Well, this is your lucky day! We’re going to show you how you can easily export your database records to RSS.

We’ll make some assumptions in this article to make things easier, and they are;

  1. you are running MS SQL that support “FOR XML”
  2. you are running ColdFusion

Ready to get started?

The first thing to do is go into your MS SQL database and create the following stored procedure that creates the RSS directly in your RDBMS.

CREATE PROCEDURE [dbo].[sp_rssProductFeed]


      SELECT            1 AS tag
                        , NULL AS parent
                        , '2.0' AS [rss!1!version]
                        , NULL AS [channel!2]
                        , NULL AS [channel!2!title!element]
                        , NULL AS [channel!2!description!element]
                        , NULL AS [channel!2!link!element]
                        , NULL AS [channel!2!language!element]
                        , NULL AS [channel!2!webMaster!element]
                        , NULL AS [channel!2!pubDate!element]
                        , NULL AS [channel!2!generator!element]
                        , NULL AS [channel!2!ttl!element]
                        , NULL AS [item!3!title!element]
                        , NULL AS [item!3!description!element]
                        , NULL AS [item!3!link!element]
                        , NULL AS [item!3!guid!element]
      SELECT            2 AS tag
                        , 1 AS parent
                        , NULL
                        , NULL
                        , 'The name of your bulk upload.' -- title
                        , 'A description of your content.' -- description
                        , '' -- link
                        , 'en-au' -- language
                        , '' -- web master
                        , CONVERT( VARCHAR( 50 ), GETDATE() ) + ' GMT' -- publication date
                        , '' -- generator
                        , 60 -- in minutes
                        , NULL
                        , NULL
                        , NULL
                        , NULL
      SELECT            3 AS tag
                        , 2 AS parent
                        , NULL
                        , NULL
                        , NULL
                        , NULL
                        , NULL
                        , NULL
                        , NULL
                        , NULL
                        , NULL
                        , NULL
                        , [title]
                        , [description]
                        , '' + CAST( productIdentity AS VARCHAR( 10 ) )
                        , productIdentity
            FROM        [your table name here]
            FOR XML EXPLICIT


When you execute this stored procedure you should get output like following (excluding the content).

<rss version="2.0">
    <title>The name of your bulk upload.</title>
    <description>A description of your content.</description>
    <pubDate>Jan  5 2008  2:35PM GMT</pubDate>
      <title>0.9m Lightweight Beach Ball</title>
      <description>"0.9m Lightweight Beach Ball    There is massive beach and poolside fun to be had with this vinyl multicolored beach ball.      Note: Image shows 1.2m ball. Actual colours may vary, primary colours used are yellow, blue and red.    0.9m in diameter it can be manually inflated or by using a standard foot pump - see  Accessories"</description>
      <title>1 x decorated weight</title>
      <description>Balloons 1 x decorated weight</description>
      <title>1 x standard weight</title>
      <description>Balloons 1 x standard weight</description>

All pretty simple so far!
The ColdFusion code to call this stored procedure is as following, just copy and paste it into a .cfm file, and run it.

            ***** Copyright 2007 Commerce Engine Pty Ltd ( *****
            You can distribute this code and use it as long as these comments
            remain in tact.

            This program is free software: you can redistribute it and/or modify
            it under the terms of the GNU General Public License as published by
            the Free Software Foundation, either version 3 of the License, or
            (at your option) any later version.

            This program is distributed in the hope that it will be useful,
            but WITHOUT ANY WARRANTY; without even the implied warranty of
            GNU General Public License for more details.

            You should have received a copy of the GNU General Public License
            along with this program.  If not, see <>.

<!--- call the stored procedure --->
"your datasource name here">
            <!--- assign a name to the resultset --->
            // get the column names data from the resultset
            columnName = rsRSSFeed.getMetaData().getColumnLabels();
            // create the path where to store the file
            storagePath = "c:\replace with where ever you want to store the file\";
            // get the coloumn name
            rssFeed = rsRSSFeed[ columnName[ 1 ] ];
<!--- write the file to disk --->

And voila! Just a few lines of code and you’re publishing RSS directly from your database. Building this structure through ColdFusion would really slow it down a lot. This actually works with thousands of records.

I hope you enjoyed this article, any questions, feel free to contact make sure you refer to the original document as we might not know which one you are referring to.

Feel free to copy and distribute this tutorial, but reference to the author and sponsor.

Author: Taco Fleur
This article was sponsored by clickfind

About This Tutorial
Author: Taco Fleur
Skill Level: Advanced 
Platforms Tested: CFMX7
Total Views: 89,098
Submission Date: January 05, 2008
Last Update Date: June 05, 2009
All Tutorials By This Autor: 2
Discuss This Tutorial

Website Designed and Developed by Pablo Varando.