Here you can find the source of getElements(Element root, String tagName, String attrName)
public static String[] getElements(Element root, String tagName, String attrName)
//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); }/*w w w.j a v a 2s .c om*/ 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); } }