Click to See Complete Forum and Search --> : Difference in the way IE deals with removeChild


Engywook
02-05-2010, 06:12 PM
I have a project where I want to:
1) load an external XML
2) read selected childnodes from the XML document
3) remove those childnodes

Here's how I'm trying to do that...

listOfNodes=srcXML.getElementsByTagName('targetTag');
while(listOfNodes.length>0) {

//get the information we are looking for from the source xml
readThis=listOfNodes[0].getElementsByTagName('ofInterest')[0].firstChild.nodeValue;
/*more of same...
...*/

//remove the node
//in IE, listOfNodes[0] refers to the same node on the next iteration
//in Chrome, it's the next node in line
listOfNodes[0].parentNode.removeChild(listOfNodes[0]);

}


In IE, I'm stuck with an orphaned node the next time I refer to listOfNodes[0]. Chrome does what I'd have expected... that is, advance the remaining nodes up the stack.

Both meanings of listOfNodes[0] are understandable, but I'm having trouble thinking of a nice way to do this that will play nicely with both.

Any suggestions? Also, which way is "right"?