Here you can find the source of getDirectChildNode(Node node, String name)
public static Node getDirectChildNode(Node node, String name)
//package com.java2s; import java.util.LinkedList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Node getDirectChildNode(Node node, String name) { Node targetNode = null;/*from w w w. j a v a 2s . c om*/ List<Node> nodes = getDirectChildNodes(node, name); if (nodes.size() == 1) { targetNode = nodes.get(0); } return targetNode; } public static List<Node> getDirectChildNodes(Node node, String name) { LinkedList<Node> nodes = new LinkedList<Node>(); NodeList childList = node.getChildNodes(); for (int childIndex = 0; childIndex < childList.getLength(); childIndex++) { Node child = childList.item(childIndex); if (child.getNodeName().equals(name)) { nodes.add(child); } } return nodes; } }