Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Scans a node and all of its children for nodes of a particular type. * * @param parent * The parent node * @param nodeName * The node name to search for * @return a List of all the nodes found matching the nodeName under the parent */ public static List<Node> getNodes(final Node parent, final String nodeName) { final List<Node> nodes = new ArrayList<Node>(); final NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { final Node child = children.item(i); if (child.getNodeName().equals(nodeName)) { nodes.add(child); } else { nodes.addAll(getNodes(child, nodeName)); } } return nodes; } }