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 { /** * Gets the nodenames of childs. * * @param dataNode * the data node * @return the nodenames of childs */ public static List<String> getNodenamesOfChilds(Node dataNode) { List<String> returnList = new ArrayList<String>(); NodeList list = dataNode.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node.getNodeType() != Node.TEXT_NODE) { returnList.add(node.getNodeName()); } } return returnList; } public static List<Node> getChildNodes(Node dataNode) { List<Node> returnList = new ArrayList<Node>(); NodeList list = dataNode.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node.getNodeType() != Node.TEXT_NODE) { returnList.add(node); } } return returnList; } }