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 { /** * Returns the content of a simple text tag If there are more than one text node or other nodetypes it will return null. * * @param node * the node * @return the simple text value from node */ public static String getSimpleTextValueFromNode(Node node) { if (node != null && node.getChildNodes().getLength() == 1 && node.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) { return node.getChildNodes().item(0).getTextContent(); } else { return null; } } 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; } }