Jump to content
Sign in to follow this  
Jayesh

Cfml ---> Xml

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>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...