Categories
Uncategorized

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">
SELECT * FROM Careers
ORDER BY Position
</cfquery>

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">

<channel>
<title>Faculty of Management - Jobs</title>
<description>Current Career Opportunities</description>
<link>http://www.uleth.ca/man/people/jobs/</link>
<cfloop query="qCareers">
<item>
<title>#Position#</title>
<description>#Details# <cfif NOT IsDefined("StartDate") OR StartDate DOES NOT CONTAIN "1999">Commences #DateFormat(StartDate,'dd mmmm yyyy')#.</cfif></description>
<link>http://www.uleth.ca/man/jobs/index.cfm?id=#RecordID#</link>
</item>
</cfloop>
</channel>

Close the cfsavecontent tag, as previously mentioned.

</cfsavecontent>

Then output the variable that contains it all.

<cfcontent type="text/xml">
<cfoutput>#theXml#</cfoutput>

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="http://www.uleth.ca/man/rss/jobs.cfm" />

Simple as that.

Like this article?

Join 19 others and become a paid supporter. Join 10 others and make a one-time donation. Join 32 others and subscribe to my monthly email newsletter.

By Kim Siever

I live in Lethbridge with my spouse and 5 of our 6 children. I’m a writer, focusing on social issues and the occasional poem. My politics are radically left. I recently finished writing a book debunking several capitalism myths. My newest book writing project is on the labour history of Lethbridge.

I’m also dichotomally Mormon. And I’m a functional vegetarian: I have a blog post about that somewhere around here. My pronouns are he/him.

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.

Leave a reply

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