Here you can find the source of getChildElement(Element parent, String tagName)
public static Element getChildElement(Element parent, String tagName)
//package com.java2s; //License from project: Apache License 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 getChildElement(Element parent, String tagName) { List<Element> children = getChildElements(parent, tagName); if (children.isEmpty()) { return null; }//from w w w.j av a2s .c om return (Element) children.get(0); } public static List<Element> getChildElements(Element parent, String tagName) { NodeList nodes = parent.getElementsByTagName(tagName); List<Element> elements = new ArrayList(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (((node instanceof Element)) && (node.getParentNode() == parent)) { elements.add((Element) node); } } return elements; } }