Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { public static void reduceChildrenList(Element elem, Class clazz) { for (int i = 0; i < elem.getChildNodes().getLength();) { if (clazz.isAssignableFrom(elem.getChildNodes().item(i).getClass())) { ++i; } else { elem.removeChild(elem.getChildNodes().item(i)); } } } }