Combining Two RSS Feeds in ColdFusion

It looks like WordPress has eaten my code samples on this one. I’ve re-written this code in CFScript and posted a fresh example. I’ve removed the blocks of code from this since they were gone anyway.

RSS TruckOne of the companies I work for posts a number of News stories on their site almost every day, and a couple of blog posts a week. The wordpress blog has an RSS feed, but the news stories do not. As part of an upcoming upgrade to the site, I decided to create an RSS Feed for the news stories as well as to provide a combined RSS feed from both sources. The cffeed tag in ColdFusion 9 makes this easy.

I did some searching and ran across Gary Gilbert’s tutorial on Creating RSS Feeds. I borrowed his code for Creating a Feed from a Query, plugged in my own query, changed a few variable names and values, and within a few minutes, I had a working, valid XML file which I could serve as the RSS Feed. Then I realized something: The date/time values in the News table were local times, not GMT. So I ended up running the query through a loop in order to “fix” the dates with the DateConvert() function prior to running the code to create an RSS feed. Worked like a charm.

Code block snipped by WordPress

I also found Ray Camden’s post on Reading a RSS Feed. This helped me understand what’s going on in this deceptively simple piece of code to read an RSS feed

Code block snipped by WordPress

Then I used a Query of Queries Union query and promptly ran into a brick wall.

Code block snipped by WordPress

The error was:

Error Executing Database Query.
Query Of Queries runtime error.
All resulting columns of queries in a SELECT statement that contains a UNION operator must have corresponding types.
Columns with index number equal 2 have diffent types (VARCHAR, BIGINT).

So apparently, even though the types look right, they’re not. I ended up having to CAST everything in the query to get it to work. And also LOL at Adobe for the spelling mistake in the last sentence!

Code block snipped by WordPress

Finally, I was able to setup the RSS Feed

Code block snipped by WordPress

At last, a working XML file, which can be served up as the RSS feed.

Now I just need to figure out the best way to generate this feed. Here’s some of my options:

  • a scheduled task to regenerate the feed periodically – how often is often enough?
  • regenerate the feed every time a news story is posted – this would only cover regeneration when a news story is added, not for a blog post.
  • manually whenever either a blog post or news story is added – easy to forget to regenerate it this way.
  • on demand when called – would always be fresh but would take more runtime.

What do you think?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s