Java XML NodeList getNodesByName(String name, NodeList nodeList)

Here you can find the source of getNodesByName(String name, NodeList nodeList)

Description

Gets all nodes with a specific name

License

Apache License

Parameter

Parameter Description
name a parameter
nodeList a parameter

Declaration

static ArrayList<Node> getNodesByName(String name, NodeList nodeList) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    /**/*from   w  ww  . j a va2 s  . c  o  m*/
     * Gets all nodes with a specific name
     * @param name
     * @param nodeList
     * @return
     */
    static ArrayList<Node> getNodesByName(String name, NodeList nodeList) {
        ArrayList<Node> nodes = new ArrayList<Node>();

        for (int i = 0; i < nodeList.getLength(); i++) {
            if (nodeList.item(i).getNodeName().equals(name)) {
                nodes.add(nodeList.item(i));
            }
        }
        return nodes;
    }
}

Related

  1. getNodeListAsList(NodeList nl)
  2. getNodeListByName(Node node, String name, List finalNodeList)
  3. getNodeListItems(NodeList nodeList)
  4. getNodeListLength(NodeList list)
  5. getNodes(String tagName, NodeList nodes)
  6. getNodesOfType(NodeList list, short type)
  7. getNodeTrimValue(NodeList nodeList)
  8. getNodeValue(NodeList nodes)
  9. getNodeValue(NodeList nodes, String tagName)