Here you can find the source of getTextContent(Element el)
Parameter | Description |
---|---|
el | the element whose text content is wanted |
public static String getTextContent(Element el)
//package com.java2s; //License from project: LGPL import org.w3c.dom.*; public class Main { /**/*from w w w.j a va2 s . co m*/ * Returns a string representing the plain text content of an element. * Any comments, attributes, elements or other non-text children * are ignored, and all CDATA and Text nodes are merged to * give a single string. * * @param el the element whose text content is wanted * @return the pure text content. If there is none, an empty * string is returned. */ public static String getTextContent(Element el) { StringBuffer sb = new StringBuffer(); for (Node child = el.getFirstChild(); child != null; child = child.getNextSibling()) { if (child instanceof Text) { Text childText = (Text) child; sb.append(childText.getData()); } } return sb.toString(); } }