Java examples for XML:XML Element Child
remove All XML Children Without Header
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static void removeAllChilderenWithoutHeader(Node node, int remainChildCount) { NodeList childNodes = node.getChildNodes(); List<Node> removeNodeList = new ArrayList<Node>(); for (int i = remainChildCount; i < childNodes.getLength(); i++) { removeNodeList.add(childNodes.item(i)); }/* w w w . j a v a 2 s .c om*/ for (Node childNode : removeNodeList) { node.removeChild(childNode); } } }