Sunday, September 14, 2008

RSS Feed to CF Query

Simple RSS to CF Query
This quick and easy function converts an RSS feed XML document into a coldfusion query for you to easily loop through and use on your website.
Files Included in this ZIP (download zip file)
rssFeed.xml An example RSS feed for this tutorial
xml.cfc CFC containing the function required
queryDump.html Dump of the resultant CF Query
1. Use CFHTTP to obtain the XML packet.
2. Then make sure it’s a valid XML packet
3. Simply invoke the CFC method and pass the function the parameters required as listed below:
• xmlPacket: A valid XML packet returned from the RSS Feed
• parentTree: The parent tree item in the RSS XML Feed
• childElement The child item containing the appropriate data required
The data will be returned to you in a CF query with the column names named exactly the same as the XML tree items.
//Get your RSS Data as you normally would<b>

<cfhttp url=""
// Make sure it’s a valid XML Packet
xmlContent = Trim(cfhttp.filecontent);
xmlContent = XMLParse(xmlContent);
// Method call to convert XML into CF query
<cfinvoke component="xml.cfc"
<cfdump var="#qXML#"> </b>

In Action
If you use the exact code above, it will fetch the RSS feed as seen in the included file (rssFeed.xml). It will then return the query as seen in the included file (queryDump.html).

No comments: