Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { public static void reduceChildrenListRecursive(Element elem) { for (int i = 0; i < elem.getChildNodes().getLength();) { Node node = elem.getChildNodes().item(i); if (node instanceof Element) { reduceChildrenListRecursive((Element) node); ++i; } else { elem.removeChild(node); } } } }