Java tutorial
//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)); } } if (required && res.size() == 0) { throw new RuntimeException("Tag " + tag + " is required in configuration file"); } return res; } }