Java XML NodeList to Element List toElements(NodeList nodes, String filter)

Here you can find the source of toElements(NodeList nodes, String filter)

Description

To elements.

License

Open Source License

Parameter

Parameter Description
nodes the nodes
filter the filter

Return

the list

Declaration

private static List<Element> toElements(NodeList nodes, String filter) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    /**//from   w w w  . j  av  a2 s .c  om
     * To elements.
     *
     * @param nodes the nodes
     * @return the list
     */
    public static List<Element> toElements(NodeList nodes) {
        return toElements(nodes, null);
    }

    /**
     * To elements.
     *
     * @param nodes the nodes
     * @param filter the filter
     * @return the list
     */
    private static List<Element> toElements(NodeList nodes, String filter) {
        List<Element> list = new ArrayList<Element>();
        for (int i = 0; i < nodes.getLength(); i++)
            if (nodes.item(i) instanceof Element) {
                Element e = (Element) nodes.item(i);
                if (filter == null || e.getTagName().equals(filter)) {
                    list.add(e);
                }
            }
        return list;
    }
}

Related

  1. toElementList(NodeList nds)
  2. toElementList(NodeList nodeList)
  3. toElementList(NodeList nodeList)
  4. toElements(NodeList nl)
  5. toElements(NodeList nodes)