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.
Tweet
Related Entries
- Parsing RSS 1.0 with ColdFusion MX - April 9, 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
Trackbacks
Trackback Address: 120/F1F9711976B297B1AE611869F770CFE1
Comments
On 04/08/2004 at 4:26:30 PM EDT Roger Benningfield wrote:
1
Why not just use:
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.
On 04/08/2004 at 4:54:45 PM EDT Pete Freitag wrote:
2
Hi Roger,
I tried that as well previously, it also returned an empty array. Were you able to get that to work?
-pete
On 04/08/2004 at 9:37:46 PM EDT Sean Corfield wrote:
3
This works:
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.
On 04/09/2004 at 12:48:47 AM EDT Pete Freitag wrote:
4
Ah! Good to know, thanks Sean!
On 04/09/2004 at 4:33:43 AM EDT Roger Benningfield wrote:
5
Pete: I took a sec to dig around in JournURL's aggregator code, and found what I'm actually using:
XmlSearch(myRSS, "//*[name()='item']")
On 06/01/2004 at 10:39:34 PM EDT Marc wrote:
6
Hey Guys, Check out this post on the CF Forums, relating to XMLSearch() when the document contains namespaces. What xpath should be used here?
http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=7&threadid=836385
On 12/14/2004 at 2:31:07 PM EST Justin wrote:
7
This seems to be the one that works best for most feeds we try to parse:
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...
On 03/07/2005 at 7:46:33 AM EST Pankaj wrote:
8
i want to read a file on particular search cretria like username="jhon" in XML using XmlSearch()
Post a Comment
Recent Entries
- Howto Install and Run the Android Emulator
- jQuery UI Autocomple IE 6 Select List z-Index Issues
- Path Traversal Vulnerability Security Hotfix for ColdFusion Released
- Using AntiSamy with ColdFusion
- Writing Secure CFML Slides from CFUnited 2010
- Locking Down ColdFusion Presentation Slides
- Cross Domain Data Theft using CSS
- Using jQuery UI Autocomplete with Hidden ID's
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...


add to del.icio.us




