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 { /** * Returns a list of the direct child {@link Element}s of the given parent. * * @param parent The parent element. */ public static List<Element> getChildElements(Element parent) { List<Element> childElements = new LinkedList<Element>(); NodeList childNodes = parent.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode instanceof Element) childElements.add((Element) childNode); } return childElements; } }