Create a New Account        Home  |  Contact  |  Login           

Zrinity is the leader in enterprise-class email marketing management solutions and content management solutions for marketing professionals and developers worldwide.
Products Services Solutions Support Resources Partners Company

Zrinity provides email marketing appliances and software to large businesses and advertising agencies. Zrinity's email delivery systems are very reliable and high-speed.

Parsing RSS with CFMX

Usign ColdFusion MX to parse a RSS feed.

Here's some code that will parse RSS 0.91, 0.92 (if well formed), and RSS 2.0 feeds. It results in an query, and uses XPath. It could probably be rewritten to perform better, but here's the first thing I came up with.

<cfhttp url="http://www.cfdev.com/newsrss.cfm" method="get" />
<cfset rss = XMLParse(cfhttp.filecontent)>

<!--- get an array of items --->
<cfset items = XMLSearch(rss, "/rss/channel/item")>
<cfdump var="#items#">
<cfset rssItems = QueryNew("title,description,link")>

<!--- loop through the array of items --->
<cfloop from="1" to="#ArrayLen(items)#" index="i">
  <cfset row = QueryAddRow(rssItems)>
  <cfset title = XMLSearch(rss, "/rss/channel/item[#i#]/title")>
  <cfif ArrayLen(title)>
    <cfset title = title[1].xmlText>
  <cfelse>
    <cfset title="">
  </cfif>
  <cfset description = XMLSearch(items[i], "/rss/channel/item[#i#]/description")>
  <cfif ArrayLen(description)>
    <cfset description = description[1].xmlText>
  <cfelse>
    <cfset description="">
  </cfif>
  <cfset link = XMLSearch(items[i], "/rss/channel/item[#i#]/link")>
  <cfif ArrayLen(link)>
    <cfset link = link[1].xmlText>
  <cfelse>
    <cfset link="">
  </cfif>
  <!--- add to query --->
  <cfset QuerySetCell(rssItems, "title", title, row)>
  <cfset QuerySetCell(rssItems, "description", description, row)>
  <cfset QuerySetCell(rssItems, "link", link, row)>
</cfloop>

<ul>
<cfoutput query="rssItems">
  <li><a href="#rssItems.link#">#rssItems.title#</a> - #rssItems.description#</li>
</cfoutput>
</ul>



More Code Samples



  


Email Marketing Best Practices Blog

home products services partners company support contact my account

Copyright 2006 © Zrinity Inc. All rights reserved.     View our privacy policy         July 8, 2008