1 Reply Latest reply on Sep 22, 2009 4:43 AM by ShardulSingh

    Update/edit xml with e4x

    rushbond Level 1

      Input xml is

      <
      
      root>
      
           <node>
      
                <id>111</id>
      
                <name>aaa</name>
      
                <lname>bbbb</lname>
      
           </node>     <
      
      
      node>
      
                <id>222</id>
      
                <name>aaa1</name>
      
                <lname>bbbb1</lname>
      
           </node>     <
      
      
      node>
      
                <id>333</id>
      
                <name>aaa2</name>
      
                <lname>bbbb2</lname>
      
           </node></
      
      
      root>
      
      
      
      

       

      Expected ouput is

       

       

      <
      
      root>
      
           <node>
      
                <id>000</id>
      
                <name>zzz</name>
      
                <lname>zzz1</lname>
      
           </node>     <
      
      
      node>
      
                <id>222</id>
      
                <name>aaa1</name>
      
                <lname>bbbb1</lname>
      
           </node>     <
      
      
      node>
      
                <id>333</id>
      
                <name>aaa2</name>
      
                <lname>bbbb2</lname>
      
           </node></
      
      
      root>
      
      
      
      

       

      I don't want to replace each child of node tag but replace entire node tag with id =111

      I am trying to use

       

       

       

      x1.node.(id==

      '111')=<node><id>000</id><name>zzz</name><lname>zzz1</lname></node>;

      not working

       

      Thanks in advance

       

       

        • 1. Re: Update/edit xml with e4x
          ShardulSingh Level 3

          Hi,

          Pls find the solution for your problem.Let me know if you have any issue.

           

          MainApplicaion.mxml

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

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

          layout="absolute">

          <mx:Script>

          <![CDATA[

          import mx.controls.Alert;

          private var xml : XML =

          <root>

          <node>

          <id>111</id>

          <name>aaa</name>

          <lname>bbbb</lname>

          </node>

          <node>

          <id>222</id>

          <name>aaa1</name>

          <lname>bbbb1</lname>

           

          </node>

          <node>

          <id>333</id>

          <name>aaa2</name>

          <lname>bbbb2</lname>

          </node>

          </root>

           

          private function onClick():void

          {

          var childList : XMLList = xml.children() as XMLList;

           

          for each (var v : Object in childList )

          {

          if(v.id == "111" )

          {

          v.id = "000";

          v.name = "zzz";

          v.lname = "zzz1";

          }

          }

          Alert.show("This is the right outPut...." +"\n"+ xml);

          }

          ]]>

          </mx:Script>

          <mx:Button label="Click Here to Get Your Expected OutPut xml" click="onClick()"/>

          </mx:Application>

           

           

           

           

          with Regards,

          Shardul Singh Bartwal