Here you can find the source of removeChildrenNode(Node node)
private static void removeChildrenNode(Node node)
//package com.java2s; //License from project: LGPL import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { private static void removeChildrenNode(Node node) { NodeList children = node.getChildNodes(); List<Node> childrenToRemove = new ArrayList<Node>(); for (int i = 0; i < children.getLength(); i++) { // node.removeChild(children.item(i)); childrenToRemove.add(children.item(i)); }/*from ww w . j a va 2 s.co m*/ for (Node child : childrenToRemove) { node.removeChild(child); } } }