Java tutorial
//package com.java2s; import java.util.LinkedList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Element[] getDirectElements(Element parent, String name) { NodeList children = parent.getChildNodes(); List<Element> result = new LinkedList<>(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeName().equals(name)) { result.add((Element) node); } } return result.toArray(new Element[0]); } }