Here you can find the source of getDirectChildNodes(final Node parent, final String... nodeNames)
Parameter | Description |
---|---|
parent | The parent node to search from. |
nodeNames | A single node name or list of node names to search for |
public static List<Node> getDirectChildNodes(final Node parent, 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 ww w .j a va2s . co m*/ * Scans a node for directly related child nodes of a particular type. This method will not scan for nodes that aren't a child of the * parent node. * * @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> getDirectChildNodes(final Node parent, final String... nodeNames) { return getChildNodes(parent, false, nodeNames); } /** * 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; } }