Title: Message

Even shorter:

 

for (var locNode:XMLNode=aNode.firstChild; locNode != null;){
        if (locNode.nodeType == 1 && locNode.nodeName=="location"){
                var exclude:Boolean = false;
                if (some condition here){
                        exclude = true;
                }              
        } 

    var nextNode = loclNode.nextSibling;

        if(exclude==true){ 

                                locNode.removeNode(); 

        }

        localNode = nextNode;
}

 
Greetz Erik
 
 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Dogra, Daman
Sent: donderdag 30 juni 2005 17:51
To: [email protected]
Subject: RE: [flexcoders] Problem using removeNode()

It surely would ....I mentioned I was having a coder's block :)
I had to modify the code a little . The "locNode=locNode.nextSibling" in the for(.....) statement made it jump two nodes instead of one .
So here's what I did...took off that line from the for () statement and added an else block (highlighted).
Thanks lot for your help, Erik.

for (var locNode:XMLNode=aNode.firstChild; locNode != null;){
        if (locNode.nodeType == 1 && locNode.nodeName=="location"){
                var exclude:Boolean = false;
                if (some condition here){
                        exclude = true;
                }              
        }
        if(exclude==true){ 

                var nextNode = loclNode.nextSibling;
                locNode.removeNode(); 

                localNode = nextNode;
        }else{
                locNode = locNode.nextSibling;

        }
}

-Daman

 

-----Original Message-----
From: Erik Westra [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 30, 2005 11:31 AM
To: [email protected]
Subject: RE: [flexcoders] Problem using removeNode()

Wouldnt this work:

for (var locNode:XMLNode=aNode.firstChild; locNode != null; locNode=locNode.nextSibling){
        if (locNode.nodeType == 1 && locNode.nodeName=="location"){
                var exclude:Boolean = false;
                if (some condition here){
                        exclude = true;
                }              
        }
        if(exclude==true){ 

                var nextNode = loclNode.nextSibling;
                loclNode.removeNode(); 

                localNode = nextNode;
        }
}

Another thing u could do i create an array with nodes to be removed, and remove them after u found out wich ones needed to be removed.
 
 
 
Greetz Erik

 

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Dogra, Daman
Sent: donderdag 30 juni 2005 16:39
To: [email protected]
Subject: [flexcoders] Problem using removeNode()

Hi All,

I am facing a Coder's block here and would appreciate help . This is kind of long and I apologize for the same .

Using actionscript I am looping some nodes (called "location") in a XML document and based on some condition would like to remove a few "location" nodes from the XML . Here's my initial code

for (var locNode:XMLNode=aNode.firstChild; locNode != null; locNode=locNode.nextSibling){
        if (locNode.nodeType == 1 && locNode.nodeName=="location"){
                var exclude:Boolean = false;
                if (some condition here){
                        exclude = true;
                }              
        }
        if(exclude==true){
                loclNode.removeNode();
        }
}

The above code does not work, because after removing the first "location" node, the loop is never executed again as loop condition locNode != null is not fullfilled (because the locNode being evaluated just got deleted).

I tried to solve this by having another pointer (called delNode) moving along with locNode and using delNode to remove nodes , while keep moving locNode on to next sibling . The problem I now face is that after delNode deletes a node, I am not able to have it catch up with locNode . Here's the code

for (var locNode:XMLNode=aNode.firstChild; locNode != null;){
        if (locNode.nodeType == 1 && locNode.nodeName=="location"){
                var exclude:Boolean = false;
                if (some condition here){
                        exclude = true;
                }
        }
        if(exclude==true){
                locNode=delNode.nextSibling;
                delNode.removeNode();
                //would like some kind of statement here to have delNode catch up with locNode
        }else{
                locNode=locNode.nextSibling;
                delNode=delNode.nextSibling;
        }
}


Would appreciate any suggestions / modifications.


Thanks
-Daman



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Computer software testing Macromedia flex Development
Software developer


YAHOO! GROUPS LINKS




Reply via email to