Here you can find the source of getElements(Element root, String tagName)
public static Element[] getElements(Element root, String tagName)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static String[] getElements(Element root, String tagName, String attrName) { NodeList list = root.getElementsByTagName(tagName); String[] result = new String[list.getLength()]; for (int i = 0; i < list.getLength(); i++) { Element el = (Element) list.item(i); result[i] = (attrName == null) ? el.getNodeName() : el.getAttribute(attrName); }/*from w w w. ja v a 2 s .co m*/ return (result); } public static Element[] getElements(Element root, String tagName) { NodeList list = root.getElementsByTagName(tagName); Element[] result = new Element[list.getLength()]; for (int i = 0; i < list.getLength(); i++) { result[i] = (Element) list.item(i); } return (result); } }