Here you can find the source of toElements(NodeList nl)
private static Element[] toElements(NodeList nl)
//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.Node; import org.w3c.dom.NodeList; public class Main { private static Element[] EMPTY_ELEMENTS = new Element[0]; private static Element[] toElements(NodeList nl) { if (nl.getLength() == 0) { return EMPTY_ELEMENTS; }//w w w . j a v a 2 s . c o m 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()]); } }