Home > coldfusion > Generate RSS Feed with ColdFusion MX

Generate RSS Feed with ColdFusion MX

Do you know how to generate RSS Feed with ColdFusion MX? If you don’t know well about CFMX, it might be complicated and fussy. But you little know about XML technology, it’s quite simple.

First of all, you need to put this, <cfsetting enablecfoutputonly=“yes”> at the top of the page. After that, output your query just like

<CFQUERY NAME=”RssQry” datasource=”MyDSN”>
SELECT *
FROM    RssTable
WHERE  Rss_status = <cfqueryparam cfsqltype=”CF_SQL_INTEGER” null=”no” value=”1″>
ORDER   BY Rss_id
</CFQUERY>

<cfsavecontent variable=”theXML”>
<cfoutput><?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
<rss version=”2.0″>
<channel>
<title>RSS</title>
<link>http://www.rss.com</link>
<description>This is Description</description>
<language>en-us</language>
<copyright>Copyright — .</copyright>
<docs>http://—–.com/rss/</docs>
<lastBuildDate>#dateformat(now(), “ddd, dd mmm yyyy”)# #timeformat(now(), “HH:mm:ss”)# EST</lastBuildDate>
</cfoutput>

<cfloop from=”1″ to=”#RssQry.RecordCount#” index=”ctr”>
<cfscript>
title = replace(RssQry.Rss_title[ctr], “<”, “&lt;”, “ALL”);
description = replace(RssQry.Rss_description[ctr], “<”, “&lt;”, “ALL”);
description = replace(description, “&”, “&amp;”, “ALL”);
description = replace(description, ‘”‘, “‘”, “ALL”);
date = dateformat(RssQry.Rss_posted_date[ctr], “ddd, dd mmm yyyy”);
time = timeformat(RssQry.Rss_posted_date[ctr], “HH:mm:ss”) & ” EST”;
author = replace(RssQry.Rss_author[ctr], “<”, “&lt;”, “ALL”);
author_email = replace(RssQry.Rss_author_email[ctr], “at>”, “@”, “ALL”);
author_email = replace(author_email, “<”, “&lt;”, “ALL”);
</cfscript>

<cfoutput>
<item>
<title>#title#</title>
<description>#description#</description>
<link>http://tutorial#RssQry.Rss_id[ctr]#.easycfm.com</link>
<author>#author_email# (#author#)</author>
<pubDate>#date# #time#</pubDate>
</item>
</cfoutput>
</cfloop>
<cfoutput>
</channel>
</rss>
</cfoutput>
</cfsavecontent>

Categories: coldfusion Tags: ,
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.