Java XML NodeList to Element List toElements(NodeList nl)

Here you can find the source of toElements(NodeList nl)

Description

to Elements

License

Apache License

Declaration

private static Element[] toElements(NodeList nl) 

Method Source Code

//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()]);
    }
}

Related

  1. toElementList(NodeList list)
  2. toElementList(NodeList nds)
  3. toElementList(NodeList nodeList)
  4. toElementList(NodeList nodeList)
  5. toElements(NodeList nodes)
  6. toElements(NodeList nodes, String filter)