pf » RSS and XPath
RSS and XPath
I came across a handy reference article on xml.com today that gives XPath queries for RSS and Atom feeds. Just last week I was attempting to parse a RSS 1.0 feed in CFMX using the XMLSearch function. I'm running into problems however due to the name spaces in RSS 1.0, here's the code I'm using:
<cfhttp url="http://www.fullasagoog.com/xml/ColdFusionMX.xml" method="get" /> <cfset rss = XMLParse(cfhttp.filecontent)> <!--- get an array of items ---> <cfset items = XMLSearch(rss, "/rdf:RDF/item")> <cfdump var="#items#">
The result is that the items array is empty. I think this is a namespace issue, but I'm not really sure. Is this a bug? Anyone have an idea?
BTW if your looking to parse RSS 0.9x or 2.0 with XPath check out this older blog post.
Related Entries
- Parsing RSS 1.0 with ColdFusion MX - April 8, 2004
- Top 10 Underrated Functions in ColdFusion - January 10, 2007
- Foundeo's 2007 End of the Year Sale - December 21, 2007
- XPath Tool - July 28, 2004
- Parsing RSS with CFMX - September 12, 2003
XmlSearch(rss, "//item")
That way you don't have to worry about what version of RSS you're parsing... you'll always get an array of items.
I tried that as well previously, it also returned an empty array. Were you able to get that to work?
-pete
XMLSearch(rss,"/rdf:RDF/:item")
as does this:
XMLSearch(rss,"//:item")
Because of the namespaces, you have to explicitly specify that 'item' has an empty namespace prefix.
XmlSearch(myRSS, "//*[name()='item']")
http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=7&threadid=836385
XmlSearch(myRSS, "//*[name()='item']")
I have a question about looping through the resulting array. What should the xpath be when looking for the description, title and item of the children?
Thanks...
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
- Googlebot to Submit Web Forms
- ColdFusion 8 Update 1 Fixes some Image Processing Quirks
- 10 Most Useful Image Functions in ColdFusion 8
- Speaking at NYC CFUG This Week
- Adobe AIR Tutorial for HTML / JavaScript Developers
- INFORMATION_SCHEMA Support in MySQL, PostgreSQL
RSS
add to del.icio.us
Pete Freitag is a software engineer, and web developer located in










