Here you can find the source of getElements(Element element, String tagName)
public static List<Element> getElements(Element element, 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.NodeList; public class Main { public static List<Element> getElements(Element element, String tagName) { final NodeList nodeList = element.getElementsByTagName(tagName); return transElements(element, nodeList); }//from w ww .j a va 2 s . co m public static List<Element> transElements(NodeList nodeList) { return transElements(null, nodeList); } public static List<Element> transElements(Element parentEle, NodeList nodeList) { final ArrayList<Element> elements = new ArrayList<Element>(); int length = nodeList.getLength(); for (int i = 0; i < length; i++) { Element element = (Element) nodeList.item(i); if (parentEle == null || element.getParentNode() == parentEle) { elements.add(element); } } return elements; } }