Java XML NodeList getNodeList(NodeList nodeList)

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

Description

Method that returns only the Element objects of the specified NodeList

License

Open Source License

Parameter

Parameter Description
nodeList the NodeList to inspect

Return

a List containing only the Element objects of the NodeList

Declaration

public static List<Element> getNodeList(NodeList nodeList) 

Method Source Code


//package com.java2s;
/*/* w  ww . j a v  a  2 s  .  c  om*/
Copyright 2012 Juan Mart?n Runge
    
jmrunge@gmail.com
http://www.zirsi.com.ar
    
This file is part of ZirUtils.
    
ZirUtils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
ZirUtils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with ZirUtils.  If not, see <http://www.gnu.org/licenses/>.
*/

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 {
    /**
     * Method that returns only the Element objects of the specified NodeList
     * 
     * @param nodeList the NodeList to inspect
     * @return a List containing only the Element objects of the NodeList
     */
    public static List<Element> getNodeList(NodeList nodeList) {
        List<Element> nodes = new ArrayList<>();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element)
                nodes.add((Element) node);
        }
        return nodes;
    }
}

Related

  1. getNodeList(Element from, String elementName)
  2. getNodeList(Node fatherNode, String nodeName)
  3. getNodeList(Node node, String tagName)
  4. getNodeList(Node pNode, String tagName)
  5. getNodeList(NodeList nl, String[] names, int pos)
  6. getNodeList(NodeList nodeList)
  7. getNodeListAsList(NodeList nl)
  8. getNodeListByName(Node node, String name, List finalNodeList)
  9. getNodeListItems(NodeList nodeList)