/** * list a set of node that match a specific filter. The list can be made * recursively or not. * @param parent the parent node to search from * @param filter the filter that children should match. * @param recurse <tt>true</tt> if you want the list to be made recursively * otherwise <tt>false</tt>. * @return the node list that matches the filter. */ public static NodeList listChildNodes(Node parent, NodeFilter filter, boolean recurse) { NodeListImpl matches = new NodeListImpl(); NodeList children = parent.getChildNodes(); if (children != null) { final int len = children.getLength(); for (int i = 0; i < len; i++) { Node child = children.item(i); if (filter.accept(child)) { matches.addElement(child); } if (recurse) { NodeList recmatches = listChildNodes(child, filter, recurse); final int reclength = recmatches.getLength(); for (int j = 0; j < reclength; j++) { matches.addElement(recmatches.item(i)); } } } } return matches; }