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:
Then the query:
<cfquery name="qCareers" datasource="xxx">
SELECT * FROM Careers
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.
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" ?>
<title>Faculty of Management - Jobs</title>
<description>Current Career Opportunities</description>
<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.
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.