Java XML NodeList extractElementsFromNodeList(NodeList config, String tag, boolean required)

Here you can find the source of extractElementsFromNodeList(NodeList config, String tag, boolean required)

Description

extract Elements From Node List

License

Open Source License

Declaration

public static List<Element> extractElementsFromNodeList(NodeList config, String tag, boolean required) 

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.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static List<Element> extractElementsFromNodeList(NodeList config, String tag, boolean required) {
        List<Element> res = new ArrayList<Element>();
        for (int i = 0; i < config.getLength(); i++) {
            Node n = config.item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(tag)) {
                res.add((Element) config.item(i));
            }/* w  w  w. j ava2 s . co m*/
        }
        if (required && res.size() == 0) {
            throw new RuntimeException("Tag " + tag + " is required in configuration file");
        }
        return res;
    }
}

Related

  1. convertToElementList(org.w3c.dom.NodeList _nodeList)
  2. copyNodeList(NodeList nodeList)
  3. createNodeCollection(final NodeList nodeList)
  4. createRealNodeList(NodeList nodeList)
  5. equalNodes(NodeList sourceNodeList, NodeList targetNodeList)
  6. extractNodeListFromElement(Element config, String tag, boolean required)
  7. fillHashtable(NodeList list, Hashtable fillIn)
  8. fillHashtable(NodeList list, Hashtable fillIn)
  9. findElement(NodeList elements, String elementName)