Here you can find the source of removeAllChildren(Element node, String elementName)
public static void removeAllChildren(Element node, String elementName)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from w ww .jav a2 s.c o m*/ * Delete children elements for Node */ public static void removeAllChildren(Node node) { if (node != null) { while (node.hasChildNodes()) { node.removeChild(node.getFirstChild()); } } } /** * Delete children elements for Element by element name */ public static void removeAllChildren(Element node, String elementName) { if (node != null) { NodeList nl = node.getChildNodes(); int len = nl.getLength(); for (int i = 0; i < len; i++) { Node childNode = nl.item(i); if (childNode != null && childNode.getLocalName() != null && childNode.getLocalName().equals(elementName)) node.removeChild(childNode); } } } }