Thursday, July 5, 2007

How to Parse XML using Coldfusion MX

XML is most widly used format to transfer data over internet. Below is the code in coldfusion which will parse a coldfusion response. I am assuming that you have stored the coldfusion response in a variable "resp"

<!--- Parse the response using XML Parse --->

<cfset xmlresp=" XMLParse(resp)">

<!--- Set the Root Element --->

<cfset rootresp=" XMLResp.XMLRoot">

<!--- Loop through the XMRoot and displaty the elements using XMLtext --->

<cfloop index="i" to="#ArrayLen(RootResp)#" from="1">

<cfset element1=" RootResp.ElementName1.XMLText">
<cfset element2=" RootResp.ElementName2.XMLText">

<!--- similary you can a access all the elements --->

</cfloop>

<!--- end of Parsing --->

That's ALL you need to do

No comments: