Here you can find the source of getElementByTagName(Element n, String elementName)
public static Element getElementByTagName(Element n, String elementName)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { public static Element getElementByTagName(Element n, String elementName) { int sz = n.getChildNodes().getLength(); ArrayList<Element> elements = new ArrayList<Element>(sz); for (int idx = 0; idx < sz; idx++) { Node node = n.getChildNodes().item(idx); if (node instanceof Element && node.getLocalName().equals(elementName)) elements.add((Element) node); }/* ww w.j a v a 2 s . com*/ if (elements.size() > 0) return elements.get(0); return null; } }