New Open-Source RSS Component
Posted on May 16, 2006
So the other day I wrote about my experimenting with Mark Mandel's javaLoader.cfc and the mjxml java library. I have put this code into a set of components that you can easily use to read rss and output RSS feeds in ColdFusion. Basically, all you need to do is supply a URL when you initialize the component. Here is an example that reads the New York Times homepage RSS feed:<cfset rss = createObject("component","rss").init("http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml") /> <P>
<cfoutput> <cfif not structIsEmpty(rss.getImage())><img src="#rss.getImage().url#" alt="#rss.getImage().title#" /></cfif> <h3 style="margin:0px;">#rss.getTitle()#</h3> <cfloop condition="#rss.hasNextItem()#"> <cfset rssItem = rss.next() /> <div style="margin-top:10px;margin-bottom:10px;"><strong><a href="#rssItem.getLink()#">#rssItem.getTitle()#</a></strong> <span style="font-size:11px;">(published on #dateFormat(rssItem.getPubDate(),"long")#)</span><br /> <cfif len(rssItem.getAuthor())>by #rssItem.getAuthor()#<br /></cfif> #rssItem.getDescription()# </div> </cfloop> </cfoutput>
Pretty simple right? You can view that example output here. You can also search for items by GUID or Title, which is a neat feature IMHO.
Ok, so now on to the limitations. It can be used to write RSS, but the underlying Java library is very limited when it comes to the setters on the rss.item class. Therefore, I have only figured out a way to set certain RSS item parameters, which negates its value substantially for writing RSS. If anyone out there knows a better Java library for doing this, I would love to hear about it (and would be happy to update the underlying code). A friend forwarded me RSSLibJ, but this (funny enough) says it is intended for writing RSS and not so much for reading (i.e. the opposite of the one I used).
You can click the download link on this post to download the code. The download includes the javaLoader.cfc and mjxml.jar as per their respective licenses. This is an early alpha of this code btw, so please notify me if there are bugs by commenting on this post.
Comments
Check out the Java Rome library:
https://rome.dev.java.net/
Posted By Brooks Andrus / Posted on 05/16/2006 at 10:50 AM
I would say you are thinking of Mark Mandel rather than me :) I coulda woulda written it if I had the need, but Mark Mandel did the JavaLoader.cfc.
MD
Posted By Mark Drew / Posted on 05/16/2006 at 12:00 PM
Woops! You are absolutely correct. I was reading your posts from this morning while writing this one which apparently screwed me up. Thanks :)
Posted By Brian Rinaldi / Posted on 05/16/2006 at 12:04 PM