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.

Categories

Strings

Comments

comments powered by Disqus