Jump to content

Cfml ---> Xml


Jayesh
 Share

Recommended Posts

here is some code that will read any well formated RSS 2.0 Feed(which is XML). Play with that and let me know if you need more help:

<br /><cftry>	<!--- get feed from site --->	<cfparam name="urltopull" default="http://www.npr.org/rss/rss.php?id=1001">	<cfhttp url="#URLToPull#" method="GET" timeout="15" />		<!--- parse xml information --->	<cfset objRSS = xmlParse(cfhttp.filecontent)>		<!--- 	<cfdump var="#objRSS#" label="RSS Feed">	<cfabort>	 --->		<!--- find length of arrary to look through --->	<cfset ArrayLength = arraylen(objRSS.rss.channel.item)>	<cfset ItemsDisplayed = 0>		<!--- loop through array to output feed --->	<cfloop index="x" from="1" to="#ArrayLength#">	<cfoutput>	<cfset ItemsDisplayed = ItemsDisplayed + 1>	<strong>#objRSS.rss.channel.item[x].title.xmltext#</strong><br />	#objRSS.rss.channel.item[x].description.xmltext#<br />	<em class="smallfont">(#objRSS.rss.channel.item[x].pubdate.xmltext#)</em><br />	<a href="#replace(objRSS.rss.channel.item[x].link.xmltext,'&','&','all')#" title="#objRSS.rss.channel.item[x].title.xmltext#" target="_blank" class="newsfeed">[view article in new window]</a><br />	<br />	</cfoutput>	</cfloop>		<!--- loop through array to output source --->	<hr />	<blockquote style="text-align:center;">	<cfset SourceLength = arraylen(objRSS.rss.channel)>	<cfloop index="x" from="1" to="#SourceLength#">	<cfoutput>	© #objRSS.rss.channel[x].copyright.xmltext#<br />	<em class="smallfont">(#objRSS.rss.channel.item[x].pubdate.xmltext#)</em><br />	<br />	<!-- 	<a href="#replace(objRSS.rss.channel[x].link.xmltext,'&','&','all')#" title="[visit topix.net in new window]" target="_blank"><img src="#objRSS.rss.channel[x].image.url.xmltext#" hspace="0" vspace="3" border="0" alt="#replace(objRSS.rss.channel[x].link.xmltext,'&','&','all')#" /></a><br />	 -->	<a href="#replace(objRSS.rss.channel[x].link.xmltext,'&','&','all')#" title="[visit topix.net in new window]" target="_blank">[visit topix.net in new window]</a><br />	<br />	</cfoutput>	</cfloop>	</blockquote>			<!--- show message if no updates --->	<cfif ItemsDisplayed EQ 0>	<cfoutput>	No articles currently available.<br />	<br />	</cfoutput>	</cfif><!--- catch errors ---><cfcatch type="any"><cfoutput>The connection to the #ucase(url.pullnewsfrom)#'s RSS feed has timed out - please try again later.  We are sorry for any inconvenience this may have caused.<br /><br /></cfoutput></cfcatch></cftry>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...