I wan to replace a node in XML document with another and as a consequence replace all it\'s children with other content. Following code should work, but for an unknown reaso
Try using replaceChild to do the whole hierarchy at once:
NodeList nodes = doc.getElementsByTagName("NodeToReplace"); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); Node newNode = // Create your new node here. node.getParentNode().replaceChild(newNode, node); }