Java tutorial
//package com.java2s; // modify it under the terms of the GNU General Public 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 { /** Return a list of the elements that are direct children of the given * node. */ public static List<Element> getChildElements(Node node) { NodeList childNodes = node.getChildNodes(); List result = new ArrayList(childNodes.getLength()); for (int i = 0; i < childNodes.getLength(); i++) { Node oneChild = childNodes.item(i); if (oneChild instanceof Element) result.add(oneChild); } return result; } }