Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
HMOKeefe #1
Limiting Output of RSS Feed
I am pulling an RSS feed into an intranet and have not figured out how to
restrict the output to the 10 most recent news items. I know I can do a TOP 10
or something similar from my own database, but how do I do this with an RSS
feed? Here is the code:
<cfhttp url="http://www.nih.gov/news/feed.xml"/> <cfset rss =
XMLParse(cfhttp.filecontent)>
<!--- get an array of items --->
<cfset items = XMLSearch(rss, "/rss/channel/item")>
<cfset channel = XMLSearch(rss, "/rss/channel")>
<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, "/rss/channel/item[#i#]/description")>
<cfif ArrayLen(description)>
<cfset description = description[1].xmlText>
<cfelse>
<cfset description="">
</cfif>
<cfset link = XMLSearch(items, "/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>
<cfset chtitle = XMLSearch(rss, "/rss/channel/title")>
<cfif ArrayLen(chtitle)>
<cfset ctitle = chtitle[1].xmlText>
<cfelse>
<cfset ctitle="">
</cfif>
<cfset chdate = XMLSearch(rss, "/rss/channel/pubDate")>
<cfif ArrayLen(chdate)>
<cfset date = chdate[1].xmlText>
<cfelse>
<cfset date="">
</cfif>
<cfset img = XMLSearch(rss, "/rss/channel/image/url")>
<cfif ArrayLen(img)>
<cfset imgurl = img[1].xmlText>
<cfelse>
<cfset imgurl="">
</cfif>
<cfoutput> <table cellpadding="5" cellspacing="1">
<tr><td><strong> #ctitle# | #date# </strong></td></tr>
</cfoutput>
<cfoutput query="rssItems">
<tr><td><b><a href="#rssItems.link#">#rssItems.title#</a></b> -
#rssItems.description#</td></tr>
</cfoutput>
</table>
HMOKeefe Guest
-
Limiting available CSS styles
We're testing Contribute as a possible solution for editing non-database-managed content for a ASP.NET 2.0 site that uses .NET Master Pages. We'd... -
Limiting connections to FMS
I was wondering if there is a notion of (to use a Java metaphor) "static" shared objects. That is objects/streams shared across FMS instances. ... -
Limiting Choises
I would like to develop a Web User Control where the user can type som text eg. e-mail, number or plain text. I would like a public property... -
Text limiting
I have a dynamic field that tells the news that Coldfusion outputs on a hompage. How can I limit the number of characters that news.News shows on... -
Limiting Old Posts
From OE, when I am viewing the newsgroups with the "Show Replies to My Messages" option checked, there are old messages from a long time ago. How... -
philh #2
Re: Limiting Output of RSS Feed
Supposing that the items array is in descending date/time order, try
<cfif arraylen(items) GT 10>
<cfloop from="1" to="10" index="i">
<cfelse>
<cfloop from="1" to="#ArrayLen(items)#" index="i">
</cfif>
HTH,
philh Guest
-
philh #3
Re: Limiting Output of RSS Feed
Oops, sorry; didn't see the rss output loop at the bottom. Try
<cfoutput query="rssItems" maxrows="10">
philh Guest
-



Reply With Quote

