3 Replies Latest reply on Aug 17, 2006 7:33 AM by inlineblue

    delete xml node

    ktucci1
      i am looking delete a node by referencing the id attribute. this sounds easy enough, but unless i am missing something, i am stumped...

      or maybe there is a better way to accomplish my goal. to simplify things, i would like to take xml bind it to a data grid and select a row from the datagrid and remove the row from the datagrid and the xml. the reason why i need it removed from the xml is for local file storage via zinc...

      thanks in advance

      ----

      var x1:XML = <x1>
      <a id = "1">AAA</a>
      <a id = "2">BBB</a>
      <a id = "3">CCC</a>
      <a id = "4">DDD</a>
      </x1>;

      delete x1.a.@id['1'];




      keith
        • 1. Re: delete xml node
          inlineblue Level 1
          It's not pretty, but it does work:

          var x: XMLList = x1.a.(@id=="1"); //Find the <a> node with id=="1"
          delete x[0]; //It should be the only item in the list
          • 2. Re: delete xml node
            ktucci1 Level 1
            thanks for the reply. i think my question may have been a bit misleading. what i am trying to do is remove a node from the xml i wish to save.

            var x1:XML = <x1>
            <a id = "1">AAA</a>
            <a id = "2">BBB</a>
            <a id = "3">CCC</a>
            <a id = "4">DDD</a>
            </x1>;

            delete x1.a.@id['1'];

            trace(x1);

            preferred output:

            <x1>
            <a id = "2">BBB</a>
            <a id = "3">CCC</a>
            <a id = "4">DDD</a>
            </x1>;
            • 3. Re: delete xml node
              inlineblue Level 1
              Yes, give it a try. That's exactly what my example does. Perhaps I should've named my variables better:

              var target: XMLList = x1.a.(@id=="1"); //Find the <a> node with id=="1"
              delete target[0]; //It should be the only item in the list