Java XML NodeList to Element List toElementList(NodeList nodeList)

Here you can find the source of toElementList(NodeList nodeList)

Description

Gets all the elements out of a NodeList .

License

Open Source License

Parameter

Parameter Description
nodeList the node list

Return

the elements

Declaration

public static List<Element> toElementList(NodeList nodeList) 

Method Source Code

//package com.java2s;

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 {
    /**//from  w w w .  j a  v a2s  .  c o m
     * Gets all the elements out of a {@link NodeList}.
     * @param nodeList the node list
     * @return the elements
     */
    public static List<Element> toElementList(NodeList nodeList) {
        List<Element> elements = new ArrayList<Element>();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element) {
                elements.add((Element) node);
            }
        }
        return elements;
    }
}

Related

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