Skip to main content
Participant
August 17, 2010
Question

How to passing cf variable xml content to SpryXMLDataSet

  • August 17, 2010
  • 1 reply
  • 640 views

I have an cf object which calls a method which returns an XML string. Now like to access the XML-data by a SpryXMLDataSet. Is this possible?

    This topic has been closed for replies.

    1 reply

    Inspiring
    August 17, 2010

    You can create a CFML page that invokes your function.  Here is a quick sample.

    <!--- set value of xmlInfo to the results of your function --->


    <cfset xmlInfo=MyFunction() />

    <!--- use CFCONTENT tag set HTTP headers appropriate to XML and output your results --->
    <cfcontent type="text/xml; charset=utf-8" reset="yes"><cfoutput>#xmlInfo#</cfoutput>


    Then specify the URL of your CFML page in the Javascript that creates the Spry data set.
    olboehlkAuthor
    Participant
    August 17, 2010

    Another solution was found (CF9):

    <cfset myCFObject = createObject("component","MyCFC").init("attribute01","attribute02")>

    <cfset CFVariableMyXMLDataString = #myCFObject.CFCFunctionGetDataAsXML()#>



    <script type="text/javascript">

    var myDataSet = new Spry.Data.XMLDataSet(null, "root/children");

    var xmlDocument = Spry.Utils.stringToXMLDoc('<cfoutput>#variables.CFVariableMyXMLDataString#</cfoutput>');

    myDataSet.setDataFromDoc(xmlDocument);

    </script>