6 Replies Latest reply on Oct 11, 2010 3:36 PM by UzairZamanSheikh

    How to edit/update data into an XML file using Flex and Actionscript

    UzairZamanSheikh

      I can read an external xml file, please see the code below:

       

      protected function button1_clickHandler(event:MouseEvent):void
      {

      var GrowthChartsDataGrid:XML;
      var loader:URLLoader = new URLLoader();
      var request:URLRequest = new URLRequest("../GrowthChartsDataGrid.xml");
         
          loader.load(request);
          loader.addEventListener(Event.COMPLETE, onComplete)

      }

       

      function onComplete (event:Event)
          {
           var loader:URLLoader = URLLoader(event.target);
           GrowthChartsDataGrid = new XML(loader.data);
          
           GrowthChartsDataGrid.GrowthChartGridView += <Month> {txtMonth.text} <Weight> {txtWeight.text} </Weight> </Month>
           texttesting.text = GrowthChartsDataGrid.toString();

          }

       

      I can read an XML file and can add an extra node and can display it in a text filed. But I want to update the XML file contents which will come from the txtMonth and txtWeight text boxes.

       

      Please any suggestions???

        • 1. Re: How to edit/update data into an XML file using Flex and Actionscript
          flex4 Level 2

          Hi

           

           

                  where do u want to update weather in xml file or in flex client side application?  if want to update data in xml file use {} binding concept for updating values and give some id for the nodes.. through that id u can update the values.. But previous values will be erased..

           

           

           

                        <root>

                              <child1 id="child1">

                                   <name>{name.text}</name>

                                   <id>{id.text}</id>

                              </child>

                         </root>

           

           

                 more over for extra information and knowledge u can go through this tutorial  http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_01.html

          • 2. Re: How to edit/update data into an XML file using Flex and Actionscript
            UzairZamanSheikh Level 1

            First of all thanks for your quick reply .

             

            I actually want to add another node inthe xml file. Files is at a local location and i can read the file and add an extra node (but I cant store this extra node in the actual XML file). But I want to save XML with the extra node.

             

            For exmaple,

             

            my current xml is:

            <?xml version="1.0" encoding="utf-8"?>

            <GrowthChartGridView>

               
                <Month> 1
                <Weight>3.5</Weight></Month>

            <Month> 2
                <Weight>3.9</Weight></Month>

            <Month> 3
                <Weight>4.5</Weight></Month>
            </GrowthChartGridView>

             

            and at run time, I can create a new node using the data from two textboxes at button click event.

                 GrowthChartsDataGrid.GrowthChartGridView += <Month> {txtMonth.text} <Weight> {txtWeight.text} </Weight> </Month>

             

            Now what I want to do is, I want to add this node back in to my XML. Therefore, the result I am looking for is, my local XML should update like this.

             

            <?xml version="1.0" encoding="utf-8"?>

            <GrowthChartGridView>

               
                <Month> 1
                <Weight>3.5</Weight></Month>

            <Month> 2
                <Weight>3.9</Weight></Month>

            <Month> 3
                <Weight>4.5</Weight></Month>

             

            <Month> {txtMonth.text} <Weight> {txtWeight.text} </Weight> </Month>  //I can read data from text boxes so its fine but I can not store this in to                                                                                                          my original XML


            </GrowthChartGridView>

             

            Thanks

            • 3. Re: How to edit/update data into an XML file using Flex and Actionscript
              hidarikani Level 2

              only Air can write files. If your app runs in a browser you will have to create a server side script (PHP, Java or some other server-side language) which updates the file.

              • 4. Re: How to edit/update data into an XML file using Flex and Actionscript
                UzairZamanSheikh Level 1

                Thank you for your reply. Is it possible to get a php or .NET code to do this please....Thanks again.

                • 5. Re: How to edit/update data into an XML file using Flex and Actionscript
                  RKaster

                  Yes, it is very possible, and I would think a mandatory exercise for dynamic content in most Flex/Flash applications. I am Flex Noob myself and still have a lot to learn. Nonetheless, I have a brother whose familiar with .NET (or ASP) and he built a program that writes the XML while I built a flex application which loads it. It works fine. Php should work as well. I would recommend the Flex in a Week tutorials if you haven't already gone through them. They provide links to PhP and .NET integration/communication.

                   

                  I hoped this help. It's a long answer to a yes and no question.

                  • 6. Re: How to edit/update data into an XML file using Flex and Actionscript
                    UzairZamanSheikh Level 1

                    Hi,

                    Thank you very much for all your support. I have managed to solve the above issues. Now my next issue is:
                    I have managed to solve the problem of using two different datasource from two different places and its working perfect now.
                    Curretnly I am plottin bothe datasources as lineseries using linechart but what I want to do is, in the same linechart, I want to show data from one datasource as lines and data from otherdata source as DOTs. Please give me some suggestions that how can I show lines as well as dots in the same graph.


                    Thanks in advance.

                    Regards,
                    Uzair