Skip navigation
Currently Being Moderated

How to create a struct from an XML?

Aug 8, 2012 4:07 AM



I am a QA and need to create a struct from an XML which is generated from a POST in the front end. I have fetched the XML generated using firebug. I need to pass the struct to a variable and use it for testing purpose.


Please can anyone help?

  • Currently Being Moderated
    Aug 8, 2012 7:12 AM   in reply to Sudeep_Tester

    ColdFusion makes this very easy for you.  Simply make a cfhttp call to retrieve your xml document.



    <cfhttp url="" method="post" timeout="10">

              <!--- include any necessary <cfhttpparam /> tags here --->




    That call will store the xml document in a variable for you; named "cfhttp" unless you specify otherwise.



    Next I like to check for success before trying to parse the xml.  Here is some pseudo code for you.



    <cfif find("200",cfhttp.StatusCode)>  <!--- check that the http call itself was successful --->

              <cfif IsXml(cfhttp.FileContent)>  <!--- check that the response is valid xml format --->

        <cfset soapResponse=xmlParse(cfhttp.FileContent) />  <!--- Convert xml text into an xml document object --->

        <cfdump var="#soapResponse#" />  <!--- Dump the xml document object --->

        <!--- At this point you have an xml object that you can then use things like xmlsearch on (and other xml functions) --->

        <!--- xmlsearch uses an XPath language expression to search an XML document object --->


        <!--- response was not xml --->



              <!--- http call failed --->




    Hope that helps.

    Mark as:
  • Currently Being Moderated
    Aug 9, 2012 7:53 AM   in reply to Sudeep_Tester

    Ok, as I mentioned before now that you have your xml document object you can perform other xml functions on that.  If you now perform an xmlSearch on your object it will parse it into a structure for you.  So adding to the code I gave you before, replace the comment referencing xmlsearch with something like:


    <cfset CommandResponse=xmlSearch(soapResponse,"//*[name()='command']") />

    <cfdump var="#CommandResponse#" />


    See what that gives you and you should be able to go from there.

    Mark as:
  • Currently Being Moderated
    Aug 15, 2012 5:33 PM   in reply to Sudeep_Tester
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points