views:

233

answers:

1

I'm working on a client's site, and updating to ColdFusion 8 isn't an option. What I'm looking for is something similar to CF8's CFFEED functionality via a custom tag or component, and I'm not particularly keen on writing my own reader/parser if something already exists.

I need to read in the RSS2 feed from a blog and display the title, description and link. Preferably I'd be able to set a cache of about 5-10 minutes so I don't hammer the feed (the information I pull from the feed will be shown on a high traffic site).

+7  A: 

If you're looking for something out of the box there are a few projects on RIAForge, a quick search brought up these two, but I'm guessing you could find more:

http://cfrss.riaforge.org/

http://rssville.riaforge.org/

If you're up for rolling your own (which I know you said you don't prefer), couldn't you just make a request for the feed like so:

<cfhttp 
  url = "http://example.com" 
  resolveurl="no"
  throwOnError = "yes"
  timeout = "10" >
</cfhttp>

and parse the results:

<cfset feedData = CFHTTP.FileContent>
<cfset xmlData = XMLParse(feedData)>

Loop through:

<cfset result = queryNew("title,description")>  
<cfset items = xmlSearch(xmlData,"//*[local-name() = 'item']")>

<cfloop index="x" from="1" to="#arrayLen(items)#">

    <cfif structKeyExists(items[x],"title")>
        <cfset node.title = items[x].title.XmlText>
    <cfelse>
        <cfset node.title = "">
    </cfif>

    <cfif structKeyExists(items[x],"description")>
        <cfset node.description = items[x].description.XmlText>
    <cfelse>
        <cfset node.description = "">
    </cfif>

    <cfset queryAddRow(result)>
    <cfset querySetCell(result,"title",node.title)>
    <cfset querySetCell(result,"description",node.description)>

</cfloop>

Output:

<cfoutput query="result">
    <ul>
        <li><strong>#title#</strong> - #description#</li>
    </ul>
</cfoutput>

Obviously untested but an idea nonetheless. Used something similar to this to get my latest delicious bookmarks. As far as caching goes, there are a few different ways to handle that. I would probably run a scheduled task to hit this file and write the output to a separate file that is included. I'm sure there are better ways, but that's the quick n dirty, imo.

jyoseph