I just wrote ann app that does this yesterday.  I'm using a CFC that gets
both arguments and a query passed in, and it spits out RSS.  I consider the
code to be "working" as opposed to "working, with an elegant
implementation".  It's still under development, so there's a lot of
"localhost" stuff in there, but this will give you a shove in the right
direction.

The CFC:

<cfcomponent displayname="RSS Component" hint="This component contains all
RSS code." style="RPC" output="Yes">
<cfsetting enablecfoutputonly="Yes">
 <cfset msg = "">
 <cfinclude template="/extensions/inc/udf_lib.cfm">
 <!---
  ***** RSS feed generator *****
 --->
 <cffunction name="generateRSSFeed" access="public" description="Generates
an RSS feed from a query result set" returntype="string" hint="">
  <cfargument name="channel_title" default="RSS Feed" required="No"
type="String">
  <cfargument name="channel_link"
default="http://#CGI.server_name#/<http:///#CGI.server_name#/>"
required="No" type="String">
  <cfargument name="channel_description" default="" required="No"
type="String">
  <cfargument name="channel_language" default="en-us" required="No"
type="String">
  <cfargument name="channel_copyright" default="c #dateformat(now(),
"yyyy")#" required="No" type="String">
  <cfargument name="channel_managingEditor" default="" required="No"
type="String">
  <cfargument name="channel_webMaster" default="" required="No"
type="String">
  <cfargument name="channel_pubDate" default="" required="No" type="String">
  <cfargument name="channel_lastBuildDate" default="" required="No"
type="String">
  <cfargument name="channel_category" default="" required="No"
type="String">
  <cfargument name="channel_generator" default="" required="No"
type="String">
  <cfargument name="channel_docs" default="" required="No" type="String">
  <cfargument name="channel_cloud" default="" required="No" type="String">
  <cfargument name="channel_ttl" type="numeric" default="60" required="no">
  <cfargument name="channel_image" default="" required="No" type="String">
  <cfargument name="channel_rating" default="" required="No" type="String">
  <cfargument name="max_rows" default="100" required="No" type="Numeric">
  <cfargument name="qryRSS" default="" required="Yes" type="query">

<cfsavecontent variable="rss">
<cfoutput><?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
 <channel>
  <title>#arguments.channel_title#</title>
  <link>#arguments.channel_link#</link>
  <description>#arguments.channel_description#</description>
  <language>#arguments.channel_language#</language>
  <copyright>#arguments.channel_copyright#</copyright><cfif len(trim(
arguments.channel_managingEditor)) GT 0>
  
<managingEditor>#arguments.channel_managingEditor#</managingEditor></cfif><cfif
len(trim(arguments.channel_webMaster)) GT 0>
  <webMaster>#arguments.channel_webMaster#</webMaster></cfif><cfif len(trim(
arguments.channel_pubDate)) GT 0>
  <pubDate>#arguments.channel_pubDate#</pubDate></cfif><cfif len(trim(
arguments.channel_lastBuildDate)) GT 0>
  <lastBuildDate>#arguments.channel_lastBuildDate#</lastBuildDate></cfif><cfif
len(trim(arguments.channel_category)) GT 0>
  <category>#arguments.channel_category#</category></cfif><cfif len(trim(
arguments.channel_generator)) GT 0>
  <generator>#arguments.channel_generator#</generator></cfif><cfif len(trim(
arguments.channel_docs)) GT 0>
  <docs>#arguments.channel_docs#</docs></cfif><cfif len(trim(
arguments.channel_cloud)) GT 0>
  <cloud>#arguments.channel_cloud#</cloud></cfif><cfif len(trim(
arguments.channel_ttl)) GT 0>
  <ttl>#arguments.channel_ttl#</ttl></cfif><cfif len(trim(
arguments.channel_image)) GT 0>
  <image>#arguments.channel_image#</image></cfif><cfif len(trim(
arguments.channel_rating)) GT 0>
  <rating>#arguments.channel_rating#</rating></cfif>
</cfoutput>
<cfloop from="1" to="#qryRSS.recordcount#" index="i">
 <cfscript>
  title = replace(qryRSS.title[i], "<", "&lt;", "ALL");
  description = replace(qryRSS.description[i], "<", "&lt;", "ALL");
  description = replace(description, "&", "&amp;", "ALL");
  description = replace(description, "'", "''", "ALL");
  author = replace(qryRSS.author[i], "<", "&lt;", "ALL");
  author_email = replace(qryRSS.author_email[i], "at>", "@", "ALL");
  author_email = replace(author_email, "<", "&lt;", "ALL");
  date = dateFormat(qryRSS.date[i], "ddd, dd mmm yyyy");
  time = timeformat(qryRSS.date[i], "HH:mm:ss") & " EST";
  guid = qryRSS.guid[i];
 </cfscript>
<cfoutput><item>
 <title>#title#</title>
 <description>#description#</description><!---
 <link>#link#</link> --->
 <author>#author_email#<cfif len(trim(author)) GT 0>
(#author#)</cfif></author>
 <pubDate>#date# #time#</pubDate>
 <guid>#guid#</guid>
</item>
</cfoutput>
</cfloop>
<cfoutput></channel>
</rss></cfoutput>
</cfsavecontent>
  <cfreturn trim(rss)>
 </cffunction>
<cfsetting enablecfoutputonly="No">
</cfcomponent>


And here's the CFM page that calls the above CFC:

<cfsetting enablecfoutputonly="yes" showdebugoutput="no">
<cfparam name="feed" default="">
<cfswitch expression="#feed#">
 <cfdefaultcase>
  <cfquery name="qryRSS" datasource="#application.dsn#">
   SELECT  C.vchContentTitle AS title, C.vchContentBody AS description,
C.dteDatePublished AS date,
      '' AS author, '[EMAIL PROTECTED]' as author_email,
      'http://localhost/?id=' + CAST(C.intContentID AS varchar(20)) AS guid
   FROM  tblContent C
   WHERE  C.dteDatePublished <= getdate() AND
      C.bitVisible = 1
  </cfquery>
  <cfset tmp.maxrows = 5>
 </cfdefaultcase>
</cfswitch>
<cfinvoke component="extensions.cfc.rss" method="generateRSSFeed"
returnvariable="rss">
 <cfinvokeargument name="channel_title" value="Test Channel">
 <cfinvokeargument name="channel_link" value="http://localhost/";>
 <cfinvokeargument name="channel_description" value="This is a test
channel.">
 <cfinvokeargument name="maxrows" value="#tmp.maxrows#">
 <cfinvokeargument name="qryRSS" value="#qryRSS#">
</cfinvoke>
<cfcontent type="text/xml">
<cfoutput>#trim(rss)#</cfoutput>
<cfsetting enablecfoutputonly="no" showdebugoutput="no">


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:275921
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to