Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import org.w3c.dom.Node; public class Main { public static ArrayList<Node> findAllChildren(final Node n, final String name) { final ArrayList<Node> retVal = new ArrayList<Node>(); for (int i = 0; i < n.getChildNodes().getLength(); i++) { if (n.getChildNodes().item(i).getNodeName().equals(name)) { retVal.add(n.getChildNodes().item(i)); } } if (retVal.isEmpty()) { throw new IllegalStateException("no " + name + " children found in: " + n.getNodeName()); } return retVal; } }