Here you can find the source of textOf(final Element el)
static String textOf(final Element el)
//package com.java2s; //License from project: Open Source License import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import org.jsoup.nodes.TextNode; import org.jsoup.select.NodeTraversor; import org.jsoup.select.NodeVisitor; public class Main { static String textOf(final Element el) { final StringBuilder accum = new StringBuilder(); new NodeTraversor(new NodeVisitor() { public void head(final Node node, final int depth) { if (node instanceof TextNode) { TextNode textNode = (TextNode) node; accum.append(textNode.text()); } else if (node instanceof Element) { Element element = (Element) node; if (element.tag().getName().equals("br")) { accum.append("\n"); }// w w w. j av a 2s . co m } } public void tail(final Node node, final int depth) { } }).traverse(el); return accum.toString().trim(); } }