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 { /** * @param name The name of the child elements you want * @return a List of child Elements */ public static List<Element> getChildren(Element element, String name) throws Exception { NodeList nodes = element.getChildNodes(); ArrayList<Element> ret = new ArrayList<Element>(nodes.getLength()); for (int i = 0; i < nodes.getLength(); i++) { Node childNode = nodes.item(i); if (childNode.getNodeName().equals(name) && childNode.getNodeType() == Node.ELEMENT_NODE) { ret.add((Element) childNode); } } return ret; } /** * @return a List of child Elements */ public static List<Element> getChildren(Element element) throws Exception { NodeList nodes = element.getChildNodes(); ArrayList<Element> ret = new ArrayList<Element>(nodes.getLength()); for (int i = 0; i < nodes.getLength(); i++) { Node childNode = nodes.item(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) { ret.add((Element) childNode); } } return ret; } }