Here you can find the source of getTextTrim(Element element)
public static String getTextTrim(Element element)
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; public class Main { public static String getTextTrim(Element element) { String txt = getText(element); return (txt == null) ? txt : txt.trim(); }//from w ww . j a v a 2 s . c om public static String getText(Element element) { StringBuffer content = new StringBuffer(); if (element != null) { NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node child = nodes.item(i); if (isText(child)) { // cast to super class that contains Text and CData content.append(((CharacterData) child).getData()); } } } return (content.length() == 0) ? null : content.toString(); } private static boolean isText(Node node) { int ntype = node.getNodeType(); return ntype == Node.TEXT_NODE || ntype == Node.CDATA_SECTION_NODE; } }