I\'m about to delete certain elements in an XML document, using code like the following:
NodeList nodes = ...; for (int i = 0; i < nodes.getLength(); i++)
Old post, but nothing marked as answer. My approach is to iterate from the end, ie
for (int i = nodes.getLength() - 1; i >= 0; i--) { // do processing, and then e.getParentNode().removeChild(e); }
With this, you needn't worry about the NodeList getting shorter while you delete.