Creating the newsfeeds is pretty straight-foward as long as the
feed is correctly formated. You can get any server-side scripting
language to generate a feed for you. Below is a code that generates
the feed of my articles. Two files will needed - a coldfusion
component (get_articles.cfc) dealing with executing a SQL query and
create_feed.cfm which obviosuly creates a feed. You may also create
a blank articles.xml file that the results will be saved to. I
split the code into a few parts, as it's easier to explain how the
code works. It's a very simplyfied version however it works quite
well and may help to understand the idea.
//get_articles.cfc
<cfcomponent output="false">
<!---globals--->
<cfset DSN = "---your datasource name---">
<cffunction name="get_articles_function" output="no"
returntype="query">
// you may specify some additional arguments
with a addition of if statementsto make this
component truly reusable
<cfquery name="get_articles" datasource="#DSN#">
SELECT articleID, atricle_title, article_content, author, date
FROM articles
</cfquery>
<cfreturn get_articles>
</cffunction>
</cfcomponent>
Following part will generate a properly formated header of the
feed:
//create_feed.cfm
<cfinvoke component="-path to the previosuly created component-"
method="get_articles" returnvariable="articles">
<cfsetting enablecfoutputonly="yes">
<cfsavecontent variable="theXML">
<cfoutput>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>Articles - Blue and Orange</link>
<description>Blue and Orange - coolest web development blog</description>
<language>en-gb</language>
<lastBuildDate>#dateformat(now(), "ddd, dd mmm yyyy")#
#timeformat(now(), "HH:mm:ss")</lastBuildDate>
</cfoutput>
Article title given in url must not contain any spaces, in this
case spaces will be replaced by _.
<cfscript>
function generate_correct_title(title) {
title = replace(title, " ","_","ALL");
return title;
}
</cfscript>
Cfloop will now produce an <item> object for every record
in a database
<cfoutput>
<cfloop query="articles">
<item>
<title>#article_title#</title>
<description>#article_content#</description>
<author>#author#</author>
<link>http://blue-and-orange.net/display/post/index.cfm/#articleID#:
#generate_correct_title(article_title)#</link>
</item>
</cfloop>
</channel>
</rss>
</cfoutput>
</cfsavecontent>
<cffile action="write" file="#expandPath(".")#articles.xml" output="#theXML#">
<h1>Feed has been created!!!</h1>
Tagged: RSS
coldfusion