Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Node getFirstValidNode(Node node) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (isValidNode(children.item(i))) return children.item(i); } return null; } public static boolean isValidNode(Node node) { return !node.getNodeName().equals("#text"); } public static boolean isValidNode(Node node, String name) { return node.getNodeName().equals(name); } }