2 Replies Latest reply on Jun 24, 2007 8:25 AM by Dan McAdam

    Modify and send XML from database

    Dan McAdam Level 1
      greetings...

      i'm populating a datagrid with XML from an HTTPService call but am unclear on how to hold changes to the data in XML format until user pushes a button to call another HTTPService to update the database?

      i've tried various ways to assign the lastResult of the HTTPService call to an XML object and update that... but can't find a way to assign the XML returned from the HTTPService call to the XML object...

      i'm using the new book by Kazoun and Lott "Programming Flex 2"
      thanks in advance
      Dan
      Salem, Oregon
        • 1. Re: Modify and send XML from database
          chris.huston.t10 Level 3
          Set a result event listener for your HTTPService call and then assign the result in this function to your XML object.

          <mx:HTTPService
          id="serviceID"
          method="POST"
          result="setResult()"
          url="yourserver.com/example.php"
          useProxy="false"/>

          ActionScript3 code:
          private var xmlVariable:XML;
          private function setResult(evt:ResultEvent):void {
          xmlVariable = XML(evt.result);
          myDataGrid.dataProvider = xmlVariable;
          }

          Depending on your xml returned from your HTTPService call, you might need to modify evt.result to evt.result.root or whatever structure you are using.

          Vygo
          • 2. Modify and send XML from database
            Dan McAdam Level 1
            very cool.... thanks so much
            i modified your example to get it to compile like this:
            ******************************************
            <mx:Script>
            <![CDATA[

            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
            import mx.controls.Alert;

            [Bindable]
            private var xmlVariable:XML;
            private function setResult(event:ResultEvent):void {
            xmlVariable = XML(event.result);
            jobFamilies.dataProvider = xmlVariable.job;
            }

            ]]>
            </mx:Script>

            <mx:HTTPService id="jobFam"
            resultFormat="e4x"
            url=" http://mywebserver.com/cea/admin_jobs.php" //not a real url
            result="setResult(event)"
            useProxy="false" />
            <mx:DataGrid x="144" y="122" width="427" id="jobFamilies" editable="true">
            <mx:columns>
            <mx:DataGridColumn headerText="Fam ID" dataField="jobid"/>
            <mx:DataGridColumn headerText="Survey ID" dataField="surveyid"/>
            <mx:DataGridColumn headerText="Family Name" dataField="familyname"/>
            </mx:columns>
            </mx:DataGrid>
            <mx:Button x="312" y="286" label="Button" click="jobFam.send();"/>

            ***************************************
            ******* the returned XML looks like this ********************
            <jobfamilies>
            <job>
            <jobid>1</jobid>
            <surveyid>1</surveyid>
            <familyname>Accounting</familyname>
            </job>
            <job>
            <jobid>2</jobid>
            <surveyid>1</surveyid>
            <familyname>Bookeeping</familyname>
            </job>
            <job>
            <jobid>3</jobid>
            <surveyid>1</surveyid>
            <familyname>Construction</familyname>
            </job>
            </jobfamilies>
            ***********************************************
            Now i can modify this XML object and return the result back to another HTTPService call... instead of having to to build a new XML structure

            best regards
            Dan
            Salem, Oregon