Java tutorial
//package com.java2s; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.util.ArrayList; import java.util.List; public class Main { public static List<Node> getElementChilds(Node parentNode) { List<Node> listChild = new ArrayList<Node>(); if (!isElement(parentNode)) { return listChild; // return empty list } else { NodeList childList = parentNode.getChildNodes(); for (int nodeId = 0; nodeId < childList.getLength(); nodeId++) { Node node = childList.item(nodeId); if (isElement(node)) { listChild.add(node); } } } return listChild; } public static boolean isElement(Node node) { return node != null && (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE); } }