a little revision to my previous post. you can also
modify this to delete 'nodes' according to supplied
attribute or index. this time it will certainly throw
null when parameter is not XMl and XMllist; returns
XMLlist if successful. I must warn you, this uses
recursion tho. Some developers feel it's not a good
practice to do so. beats me, i just need it to work :P

And oh of course this only works on the as3 xml . not
on the legacy XMLNode  from as2. PLease let me know if
you have optimized/clean up the code and the logic
itself. Ill certainly be using it in a project im
working in. thnx!

public  function
deleteDescendantsByName(a:*,nodeName:String):XMLList{
                        
                        var r:XMLList=null;
                                        
                        if (a.length()>=1&&((a is XML)||(a is XMLList))){
                                r = new XMLList();                      
                                for (var i:int=0;i<a.length(); i++){
                                        
                                        if (a[i].name().localName!=nodeName){
                                                if 
(a[i].descendants(nodeName).length()==0){
                                                        r+=a[i];        
                                                }else{
                                                        var
t:XMLList=deleteDescendantsByName(a[i].children(),nodeName);
                                                        a[i].setChildren(t);
                                                        r+=a[i];
                                                }
                                        
                                        }
                          }
                }
                return r;
        }


 
____________________________________________________________________________________
Food fight? Enjoy some healthy debate 
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367

Reply via email to