Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static List<Node> getAllChildNodes(Node node) { if (node == null) return null; List<Node> result = new ArrayList<Node>(); NodeList nodelist = node.getChildNodes(); for (int i = 0; i < nodelist.getLength(); i++) { Node curnode = nodelist.item(i); int type = curnode.getNodeType(); if (type != Node.TEXT_NODE) result.add(nodelist.item(i)); List<Node> childlist = getAllChildNodes(curnode); if (childlist != null) result.addAll(childlist); } return result; } }