Java HTML Jsoup Element collectTextUntilNextTag(final Element header, final String nextTagName)

Here you can find the source of collectTextUntilNextTag(final Element header, final String nextTagName)

Description

collect Text Until Next Tag

License

Open Source License

Declaration

static String collectTextUntilNextTag(final Element header, final String nextTagName) 

Method Source Code

//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();
    }
}

Related

  1. addTag(Element e, String tagName)
  2. appendFragment(Element e, String fragment)
  3. appendText(Element element, StringBuffer stringBuffer)
  4. childrenByTag(final Element element, final String tag)
  5. collectItemRewards(final Element icontab, final BiConsumer collector)
  6. containsLink(Element element, String link)
  7. convertLinksToStrings(Elements links)
  8. convertNodeToText(Element element)
  9. convertTablesToDivs(Element body)