Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

How do I parse RSS feeds?

RSS is a form of syndication in use by almost all blogs and many other types of web sites. It is a simple way to list, via XML, the latest content that has been updated on a web site. While parsing XML isn't difficult in ColdFusion, to work with RSS you have to have a good understanding of both the multiple "flavors" or RSS in use today as well a deep understanding of how the content is encoded within the XML. Luckily ColdFusion makes this relatively easy with the <CFFEED> tag.

As a simple example, consider this code:

<cffeed source="http://www.coldfusionjedi.com/rss.cfm" query="content">
<cfdump var="#content#">

The source used in the <cfeed> tag simply points to the RSS file for the site. The query attribute tells ColdFusion to parse the RSS data into a query. You can also use the name attribute to create a structure of data.

In general, that's all you have to do. Sometimes though you do need to know a bit more about the RSS being used in order to properly use it. If you add the properties attribute than ColdFusion will return a structure of data about the RSS feed itself:

<cffeed source="http://www.coldfusionjedi.com/rss.cfm" query="content" properties="p">

This can help you determine the best way to use the parsed data.


This question was written by Raymond Camden.
It was last updated on December 20, 2008 at 9:33:56 AM EST.

CFML Referenced

<cffeed>

Categories

Strings

Comments

Comment made by George Bridgeman on December 19, 2008 at 9:06 AM
There are a number of issues with CFFEED which Ray has written about. Do a search on his site and you'll find most of them.

George.


Comment made by Raymond Camden on December 19, 2008 at 9:32 AM
Yep, I know that, as I'm the guy who wrote this article too. ;) While CFFEED has issues, it is the way you parse RSS in CF, and has gotten much better with the latest updates.