I recently found a ColdFusion script that allows you parse an RSS feed:
http://www.activsoftware.com/code_samples/code.cfm/CodeID/125/ColdFusion/Parsing_RSS_with_CFMXHowever, although I was able to get the example to work with one of my own RSS urls, I routinely (in fact, more often than not) get the following error messages when trying to view the feed:
Document root element is missing
When it works, however, it works fairly well:
http://64.139.139.245/parse_rss_test.cfm (this example shows the feed in an auto-scrolling CSS layer)
Anyways, .. I tried coding around the error with cftry/cfcatch blocks, but the errors still occur and get displayed frequently. I have mainly 2 questions that I'd like to have answered:
1. Why does the script (code is below) routinely fail like that? Is there a better way to parse an xml feed than the method I'm using below, .. or a way to code around the errors? If so how? (Sample replacement code would be ideal)
2. Would it be possible for me to reduce the sizes of the images displayed in the feed to, .. say, 50% of their current display size? If so, how? If this is not possible, then woudl it be possible to just remove the images altogether? If so, how?
Thanks in advance,
- Yvan
p.s. My ColdFusion code is below:
--------------------------
----------
----------
----------
----------
----------
------
<cfhttp url="
http://www.xanadb.com/ticker/MSFT+AAPL+AN+BBX+GPI+LEN+NSANY+ODP+OMC+PZZA+SKFB.PK+TGT" method="get" />
<cfset rss = XMLParse(cfhttp.fileconten
t)>
<cfset items = XMLSearch(rss, "/rss/channel/item")>
<cfset rssItems = QueryNew("title,descriptio
n,link")>
<cfloop from="1" to="#ArrayLen(items)#" index="i">
<cfset row = QueryAddRow(rssItems)>
<cfset title = XMLSearch(rss, "/rss/channel/item[#i#]/ti
tle")>
<cfif ArrayLen(title)>
<cfset title = title[1].xmlText>
<cfelse>
<cfset title="">
</cfif>
<cfset description = XMLSearch(items[i], "/rss/channel/item[#i#]/de
scription"
)>
<cfif ArrayLen(description)>
<cfset description = description[1].xmlText>
<cfelse>
<cfset description="">
</cfif>
<cfset link = XMLSearch(items[i], "/rss/channel/item[#i#]/li
nk")>
<cfif ArrayLen(link)>
<cfset link = link[1].xmlText>
<cfelse>
<cfset link="">
</cfif>
<cfset QuerySetCell(rssItems, "title", title, row)>
<cfset QuerySetCell(rssItems, "description", description, row)>
<cfset QuerySetCell(rssItems, "link", link, row)>
</cfloop>
<table cellpadding='2' border='0' cellspacing='0'>
<tr>
<cfoutput query="rssItems">
<td><a href="#rssItems.link#">#rs
sItems.tit
le#</a> - #rssItems.description#</td
>
</cfoutput>
</tr>
</table>
--------------------------
----------
----------
----------
----------
----------
------
Start Free Trial