Here you can find the source of getElements(Document document, Element parent)
public static Element[] getElements(Document document, Element parent)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { private static Element[] EMPTY_ELEMENTS = new Element[0]; public static Element[] getElements(Document document, Element parent) { if (parent == null) { return new Element[] {}; }// w w w . j a va 2 s.co m NodeList nl = parent.getChildNodes(); return toElements(nl); } private static Element[] toElements(NodeList nl) { if (nl.getLength() == 0) { return EMPTY_ELEMENTS; } List<Element> al = new ArrayList<Element>(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n instanceof Element) { al.add((Element) n); } } return al.toArray(new Element[al.size()]); } }