Get Text Content from Xml Node
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
*
* $Id: Dom.java 123 2010-07-20 12:01:48Z chris@rosaloves.com $
*
* @author clewis Jul 18, 2010
*
*/
class Dom {
public static String getTextContent(Node n) {
StringBuffer sb = new StringBuffer();
NodeList nl = n.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node child = nl.item(i);
if (child.getNodeType() == Node.TEXT_NODE)
sb.append(child.getNodeValue());
}
return sb.toString();
}
}
Related examples in the same category