Posted this on Flash_tiger without any luck. I know about using delete
in E4X XML to delete unwanted XML nodes, but how would you hunt down
through and delete any nodes (of a specific type, say module nodes
in the example below) that don't have any children?
For example, if myXML happens to
This might get you pointed in the right direction. You can get an
XMLList of all the empty nodes by this kind of statement
xml.modules.module.(children().length() == 0);
but if you then try a simple delete on that
delete xml.modules.module.(children().length() == 0);
you get: Delete
Filter the XML using E4X and then make a new XML from that filtered
result.
var xml:XML = xml
modules
module title=apple/
module title=orange
node/
/module
module title=banana
Actually, you don't need that newXML var. Sorry. I left that in
during debugging.
Just setChildren the original xml, as I did. If you want to make a
copy without destroying the original, then setChildren() the newXML
var instead.
___
Since Jason wanted to get rid of all the nodes that were empty he
would want to filter against !=0 and then use setChildren to refresh
his original xml. Using setChildren is a nifty trick, much nicer than
that delete loop I put out there.
Rob
On 9-Jun-09, at 12:24 PM, Steven Sacks wrote:
:25 PM
To: Flash Coders List
Subject: Re: [Flashcoders] XML find and delete nodes
Filter the XML using E4X and then make a new XML from that filtered
result.
var xml:XML = xml
modules
module title=apple/
module title=orange
node
: Tuesday, June 09, 2009 12:20 PM
To: Flash Coders List
Subject: Re: [Flashcoders] XML find and delete nodes
This might get you pointed in the right direction. You can get an
XMLList of all the empty nodes by this kind of statement
xml.modules.module.(children().length() == 0);
but if you then try
Once you really dig into E4X and realize the crazy stuff you can do,
it's amazing.
I do some pretty crazy E4X parsing, filtering and validation with
Gaia. Here are some examples:
// get all nodes named page or asset in the entire XML
var nodes:XMLList = xml.descendants().(name() == page
8 matches
Mail list logo