I\'m building a script which has to patch XML files, including replacing one list of elements with another. The following function applies a patch (involving a possibly empt
Building on the diagnosis by @Maurice and @fahd...
Can't you just put a condition before
parent.removeChild(node);
such as
if (parent.isSameNode(node.getParentNode()))
Then it would only remove a direct child of the given parent.