Here you can find the source of collectTextUntilNextTag(final Element header, final String nextTagName)
static String collectTextUntilNextTag(final Element header, final String nextTagName)
//package com.java2s; //License from project: Open Source License import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import org.jsoup.nodes.TextNode; public class Main { static String collectTextUntilNextTag(final Element header, final String nextTagName) { final StringBuilder sb = new StringBuilder(); for (Node node = header.nextSibling(); !(node instanceof Element && ((Element) node).tagName().equals(nextTagName)); node = node.nextSibling()) { if (node instanceof TextNode) { sb.append(((TextNode) node).text()); } else if (node instanceof Element && ((Element) node).tagName().equals("br")) { sb.append("\n"); }//from w w w.j a v a 2 s . c o m } return sb.toString(); } }