RSS and ColdFusion

RSS is rapidly becoming a popular format for providing content. It allows users to subscribe to bits of information, so they can be notified when new information has been posted.
I’ve been tossing around the idea of implementing RSS at work lately, and wanted to do it with ColdFusion. I finally buckled down and put something together. Surprisingly, it was much easier to do that I thought it would be, and I ended up creating RSS feeds for news articles, upcoming events, and job opportunities.
Here’s the process I used to create the RSS feed for job opportunities.
The first thing in my CFM file is a block of code that makes sure no HTML outside of the cfoutput tag gets displayed:
<cfsetting enablecfoutputonly="yes">
Then the query:
<cfquery name="qCareers" datasource="xxx">
ORDER BY Position

Then I implement a cfsavecontent tag. This makes sure that all the content between these two tags is saved as a variable. The closing tag appears later.
<cfsavecontent variable="theXML">
Then comes my output. It is important than the root tag in XML for an RSS feed is “channel”, that the title of the feed is in a “title” tag, feed description is in “description”, a link to the HTML content of the feed is in a “link” tag. As well, every item should be within an “item” tag, which also contains “title”, “description” and “link” tags. Not following that format will cause your RSS feed to fail.
In addition, there must be an “rss” tag, and there must be no white space (including a new line) between the opening “cfoutput” tag and the “xml” tag.
<cfoutput><?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">

<title>Faculty of Management - Jobs</title>
<description>Current Career Opportunities</description>
<cfloop query="qCareers">
<description>#Details# <cfif NOT IsDefined("StartDate") OR StartDate DOES NOT CONTAIN "1999">Commences #DateFormat(StartDate,'dd mmmm yyyy')#.</cfif></description>

Close the cfsavecontent tag, as previously mentioned.
Then output the variable that contains it all.
<cfcontent type="text/xml">

Simply upload this file to your server somewhere, and add the following into the page where you want the RSS feed available.
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="" />
Simple as that.

Support independent journalism

By Kim Siever

Kim Siever is an independent queer journalist based in Lethbridge, Alberta. He writes daily news articles, focusing on politics and labour.

6 replies on “RSS and ColdFusion”

You have NOOOOOO idea how helpfull this article was. I was going CrAzY with this damn RSS feed. I am new to CF from an HTML background. Thanks for the info.

Thanks so much! I was worried that ColdFusion 5.0 couldn’t handle an RSS feed (other tutorials used cfxml which isn’t featured in 5.0) but it turned out to be no problem in the end.

Comment on this story

This site uses Akismet to reduce spam. Learn how your comment data is processed.