Java tutorial
//package com.java2s; /** * This file belongs to the BPELUnit utility and Eclipse plugin set. See enclosed * license file for more information. */ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * * @return one large string with the contents of all TextNodes, or null if * there are non text nodes or no text nodes as children. */ public static String getContentsOfTextOnlyNode(Node n) { NodeList children = n.getChildNodes(); if (children.getLength() == 0) { return null; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.TEXT_NODE) { sb.append(node.getNodeValue()); } else { return null; } } return sb.toString(); } }