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 operator is not supported with operand of type XMLList.
I'm not sure right now why that wouldn't work. But you could simply loop through the XMLList generated and do a delete on each node

var emptyModule:XMLList = xml.modules.module.(children().length() == 0);
var index:int = emptyModule.length() - 1;
for(var i = index; i > - 1; i--){
        delete emptyModule[i];
}
trace(xml);

hth,

Rob

PS so as far as the delete operator I'm not sure why delete(xml.modules.module) works while something like delete(xm.modules.module.(@title == "apple")) gives an error like above. I would think that both those "querries" result in an XMLList, in the first case the delete occurs but not in the second... maybe some lunch will help my brain work better.





On 9-Jun-09, at 11:02 AM, Merrill, Jason wrote:

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 look like:

<xml>
        <modules>
                <module title="apple"/>
                <module title="orange">
                        <node/>
                <module>
                <module title="banana">
                        <node/>
                <module>
                <module title="plum"/>  
                <module title="pear"/>
                <module title="pineapple">
                        <node/>
                <module>
        </modules>
</xml>

then with that structure, I would want my code to remove the <module>
nodes that have the "title" attribute values of "apple", "plum", and
"pear" since those have no child nodes.

I know I could figure it out through enough trial and error, but I've
spent enough time on it already.  Thought someone here could give a
quick answer. Thanks!


Jason Merrill

Bank of  America  Global Learning
Shared Services Solutions Development

Monthly meetings on the Adobe Flash platform for rich media experiences
- join the Bank of America Flash Platform Community

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to