Java tutorial
//package com.java2s; 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 { /** * Returns a List of all child Elements of the given Element. * * @param element the element from which to retrieve child elements * @return a List of child Elements. * @throws NullPointerException if the element is null. */ public static List getChildElements(Element element) { if (element == null) throw new NullPointerException("Tried to get child elements on a null element"); List result = new ArrayList(); NodeList children = element.getChildNodes(); for (int i = 0; i != children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { result.add(children.item(i)); } } return result; } }