Here you can find the source of getElementList(NodeList list)
Parameter | Description |
---|---|
list | Nodelist containing all types of nodes (text nodes etc.) |
public static List<Element> getElementList(NodeList list)
//package com.java2s; //License from project: LGPL 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 ww. ja v a 2 s . c om*/ * Filters all elements of a NodeList and returns them in a collection. * * @param list Nodelist containing all types of nodes (text nodes etc.) * @return a list containing all elements from nodeist, but not containing other nodes such as text nodes etc. */ public static List<Element> getElementList(NodeList list) { List<Element> col = new ArrayList<>(list.getLength()); for (int i = 0; i < list.getLength(); i++) { if (list.item(i) instanceof Element) { col.add((Element) list.item(i)); } } return col; } /** * Filters all elements of a NodeList and returns them in a collection. The list will only contain that elements of * the NodeList that match the specified node name. The name selection is case insensitive. * * @param list Nodelist containing all types of nodes (text nodes etc.) * @param nodeNames the name of the elements to be selected (case insensitive) * @return a list containing all elements from nodelist, but not containing other nodes such as text nodes etc. */ public static List<Element> getElementList(NodeList list, String... nodeNames) { List<Element> col = new ArrayList<>(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); if (item instanceof Element) { for (String nodeName : nodeNames) { if (item.getNodeName().equalsIgnoreCase(nodeName)) { col.add((Element) item); break; } } } } return col; } }