Here you can find the source of getNameToFirstNode(Node parent, String node_name)
public static Node getNameToFirstNode(Node parent, String node_name)
//package com.java2s; //License from project: LGPL import org.w3c.dom.*; import java.util.ArrayList; import java.util.List; public class Main { public static Node getNameToFirstNode(Node parent, String node_name) { if (parent == null || node_name == null) return null; Node[] nodes = getNameToNodeList(parent, node_name); return node_name.length() > 0 ? nodes[0] : null; }//from w w w.j a va2 s . c o m public static Node[] getNameToNodeList(Node parent, String node_name) { List<Node> nodes = new ArrayList<>(); if (parent == null || node_name == null) return nodes.toArray(new Node[0]); NodeList list = parent.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node.getNodeName().equals(node_name)) { nodes.add(node); } } return nodes.toArray(new Node[0]); } }