One way to do it is to look for the child elements which id is *not* "b".
Then replace the original child elements with the new ones, or in other words, set the remaining elements as the children of the
parent:
var s:String = '<parent><child id="a" /><child id="b" /><child id="a" /><child id="b"
/></parent>';
var xml:XML = new XML(s);
trace("before: ", xml.toXMLString());
trace("----------");
var elements:XMLList = xml.child.(@id != "b");
trace("elements: ", elements.toXMLString());
trace("----------");
xml.setChildren(elements);
trace("after: ", xml.toXMLString());
//output:
before: <parent>
<child id="a"/>
<child id="b"/>
<child id="a"/>
<child id="b"/>
</parent>
----------
elements: <child id="a"/>
<child id="a"/>
----------
after: <parent>
<child id="a"/>
<child id="a"/>
</parent>
regards,
Muzak
----- Original Message -----
From: "Joel Stransky" <j...@stranskydesign.com>
To: "Flash Coders List" <flashcoders@chattyfig.figleaf.com>
Sent: Monday, March 09, 2009 4:38 AM
Subject: [Flashcoders] find and delete XML nodes
I have some xml nodes where I need to evaluate their attributes and delete
them if they meet certain criteria. It's probably simple but its late and
brain fatigue is setting in.
Say I had this node
<parent>
<child id="a" />
<child id="b" />
<child id="a" />
<child id="b" />
</parent>
How would I find and delete any <child> who's id is "b" ?
--
--Joel Stransky
stranskydesign.com
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders