2 Replies Latest reply on May 16, 2006 4:45 AM by slaskis

    Remove node from XML with E4X

    slaskis
      How do i do it? I've tried "delete node;" or even node = null;
        • 1. Re: Remove node from XML with E4X
          Level 7
          Works for me.

          public var xml:XML = <body><p>Paragraph 1</p><p>Paragraph
          2</p><who>what</who></body>;
          delete xml.who;
          //delete xml.p[1];
          //delete xml.children ()[0];
          trace (xml);

          "slaskis" <webforumsuser@macromedia.com> wrote in message
          news:e4c9ah$6dq$1@forums.macromedia.com...
          > How do i do it? I've tried "delete node;" or even node = null;
          >


          • 2. Re: Remove node from XML with E4X
            slaskis Level 1
            Ok, i found a solution to it...

            The problem was first of all mostly that i was trying to do it dynamically, without really telling the name of the child that i would like to remove.

            So, if it was only this that needed to be done:
            delete xml.hello;
            and the xml looks like
            <xml>
            <hello>something</hello>
            </xml>
            it would work. But now i tried to remove a node without knowing the name of it.
            but it works when i did like this:


            var node : XML = XML( checkbox.data.node );
            var nodeParent : XML = node.parent();
            delete nodeParent[node.name()][node.childIndex()];

            And it works!

            I don't know if it's the best way, but it works and i'm happy...