Here you can find the source of getNodes(final Node parent, final String nodeName)
Parameter | Description |
---|---|
parent | The parent node |
nodeName | The node name to search for |
public static List<Node> getNodes(final Node parent, final String nodeName)
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from w ww .j ava2 s. com*/ * 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; } }