Jayesh Posted September 30, 2006 Share Posted September 30, 2006 anybody can guide me to get data from Xml using Cfml ..?i want to get data from xml and convert it into cfquery .... Link to comment Share on other sites More sharing options...
Skemcin Posted October 2, 2006 Share Posted October 2, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now