Here you can find the source of getChildElementByName(Element parent, String name)
public static Element getChildElementByName(Element parent, String name)
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Element getChildElementByName(Element parent, String name) { List<Element> children = getChildElementsByName(parent, name); if (children.size() == 0) { return null; }//from w w w . java2s . com if (children.size() > 1) { throw new RuntimeException("Unexpected number of '" + name + "' elements " + children.size()); } return children.get(0); } public static List<Element> getChildElementsByName(Element parent, String name) { List<Element> result = new ArrayList<Element>(); NodeList childNodes = parent.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child.getNodeType() != Node.ELEMENT_NODE) { continue; } String nodeName = child.getNodeName(); if (name.equals(nodeName.trim())) { result.add((Element) child); } } return result; } }