cfRssFeed(feedURL[, amount])
Last updated November 20, 2008
Version: 2 | Requires: CF6 | Library: StrLib
Description:
This UDF display's a rss feed to a web browser, in a readable format.
Return Values:
Returns a query.
Example:
<cfinclude template="rssfeedUdf.cfm">
<cfset rssFeed = cfRssFeed("http://news.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml")>
<font face="arial" size="2">
<ul>
<cfoutput query="rssFeed">
<li><b><a href="#link#">#title#</a></b> - #description#</li><br>
</cfoutput>
</ul>
</font>
Parameters:
Name | Description | Required |
---|---|---|
feedURL | RSS URL. | Yes |
amount | Restricts the amount of items returned. Defaults to number of items in the feed. | No |
Full UDF Source:
<!---
Display rss feed.
Changes by Raymond Camden and Steven (v2 support amount)
@param feedURL RSS URL. (Required)
@param amount Restricts the amount of items returned. Defaults to number of items in the feed. (Optional)
@return Returns a query.
@author Jose Diaz-Salcedo (bleachedbug@gmail.com)
@version 2, November 20, 2008
--->
<cffunction name="cfRssFeed" access="public" returntype="query" output=false>
<cfargument name="feedUrl" type="string" required="true"/>
<cfset var news_file = arguments.feedurl>
<cfset var rss = "">
<cfset var items = "">
<cfset var rssItems = "">
<cfset var i = "">
<cfset var row = "">
<cfset var title = "">
<cfset var link = "">
<cfhttp url="#news_file#" method="get" />
<cfset rss = xmlParse(cfhttp.filecontent)>
<cfset items = xmlSearch(rss, "/rss/channel/item")>
<cfset rssItems = queryNew("title,description,link")>
<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>
<cfset querySetCell(rssItems, "title", title, row)>
<cfset querySetCell(rssItems, "description", description, row)>
<cfset querySetCell(rssItems, "link", link, row)>
</cfloop>
<cfreturn rssItems />
</cffunction>
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016