Here you can find the source of removeChildElements(Element parent)
public static void removeChildElements(Element parent)
//package com.java2s; /*/*from w ww.java2 s . com*/ * ==================================================================== * This software is subject to the terms of the Common Public License * Agreement, available at the following URL: * http://www.opensource.org/licenses/cpl.html . * Copyright (C) 2003-2004 TONBELLER AG. * All Rights Reserved. * You must accept the terms of that agreement to use this software. * ==================================================================== * * */ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * removes all children of element type */ public static void removeChildElements(Element parent) { List v = getChildElements(parent); Iterator en = v.iterator(); while (en.hasNext()) parent.removeChild((Node) en.next()); } /** * returns List of all direct child elements */ public static List getChildElements(Node parent) { ArrayList retVec = new ArrayList(); NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { retVec.add(children.item(i)); } } return retVec; } }