Dynamic RSS with XML and Coldfusion

Posted on 2006-05-24
Medium Priority
Last Modified: 2013-12-20
Hello Experts,

I realize there are many postings already about this, but I have not found my particular answer.
When I save the code below as a .cfm file, it works just fine.  The database is queried each time and the output is produced in an xml fasion.

Most xml news feeds that I see are in .xml format.  When I save the same code in .xml, it does not validate or produce the xml newsfeeds, but rather gives me an error.  How do I get the newsfeed to work in an .xml file but still use coldfusion??  What are my options?


<cfsetting enablecfoutputonly="yes">
<cfset NumberOfFeedItems = 5>

<cfquery name="getNews"
SELECT TOP #NumberOfFeedItems# *
FROM mytable
ORDER BY somefield DESC

<cfset theDatetime = "#dateformat(now(),
"ddd, dd mmm yyyy")# #timeformat(now(),
"HH:mm:ss")# MST">

<cfsetting enablecfoutputonly="yes">
<cfsavecontent variable="theXML">

<cfoutput><?xml version="1.0" encoding="ISO-8859-1" ?>
      <!--  RSS generated by Me on #theDatetime#-->
      <rss version="2.0">
            <title>Me </title>
            <link>my link</link>
            <description>My description</description>
            <copyright>My copyright</copyright>

      <cfloop FROM="1" to = "#numberOfFeedItems#" index="ctr">
              title = replace(getNews.Title[ctr], "<", "&lt;", "ALL");
              body = replace(getNews.body[ctr], "<", "&lt;", "ALL");
              body = replace(body, "&", "&amp;", "ALL");
              summary = replace(getNews.summary, "&", "&amp;", "ALL");
              newsdate = dateformat(getNews.newsdate[ctr], "ddd, dd mmm yyyy");
              time = timeformat(getNews.newsdate[ctr], "HH:mm:ss")&"MST";
                        <!--- <pubDate>#newsdate# #time#</pubDate> --->

<cfcontent type="text/xml">
Question by:jhmoen
  • 2

Expert Comment

ID: 16793111
That is a tricky question. If the CFM file is outputting valid XML now, then it should work as an XML feed. Remember that the client (whether a browser or reader) will only get the XML that is output, not the ColdFusion code. If you view the source of the output and it is valid, it should work as-is.

You could add an association to your web site that defines .XML as a ColdFusion file type, but that is a hack and may cause problems elsewhere.


Accepted Solution

ExpertAdmin earned 375 total points
ID: 17051860
I think that if no points are to be refunded, then I should get credit for my answer.


Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question