One 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.
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
Then I used a Query of Queries Union query and promptly ran into a brick wall.
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!
Finally, I was able to setup the RSS Feed
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?
