Here you can find the source of getChildNodes(final Node parent, boolean recursiveSearch, final String... nodeNames)
Parameter | Description |
---|---|
parent | The parent node to search from. |
recursiveSearch | If the child nodes should be recursively searched. |
nodeNames | A single node name or list of node names to search for |
protected static List<Node> getChildNodes(final Node parent, boolean recursiveSearch, final String... nodeNames)
//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 w w .j a v a 2 s . c o m*/ * Scans a node and all of its children for nodes of a particular type. * * @param parent The parent node to search from. * @param nodeNames A single node name or list of node names to search for * @return A List of all the nodes found matching the nodeName(s) under the parent */ public static List<Node> getChildNodes(final Node parent, final String... nodeNames) { return getChildNodes(parent, true, nodeNames); } /** * Scans a node and all of its children for nodes of a particular type. * * @param parent The parent node to search from. * @param recursiveSearch If the child nodes should be recursively searched. * @param nodeNames A single node name or list of node names to search for * @return a List of all the nodes found matching the nodeName under the parent */ protected static List<Node> getChildNodes(final Node parent, boolean recursiveSearch, final String... nodeNames) { 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); for (final String nodeName : nodeNames) { if (child.getNodeName().equals(nodeName)) { nodes.add(child); } if (recursiveSearch) { nodes.addAll(getChildNodes(child, true, nodeName)); } } } return nodes; } }