public static String getPlainHtml(Element element) {
    FormattingVisitor formatter = new FormattingVisitor();
    NodeTraversor traversor = new NodeTraversor(formatter);
    traversor.traverse(element); // walk the DOM, and call .head() and .tail() for each node

    return formatter.toString();
  }
Exemple #2
0
  /**
   * @param htmlText
   * @return
   */
  public static String htmlToPlainText(String htmlText) {
    // replace the blanks in previous
    htmlText = htmlText.replaceAll(" ", "");

    Document doc = Jsoup.parse(htmlText);
    FormattingVisitor formatter = new FormattingVisitor();
    NodeTraversor traversor = new NodeTraversor(formatter);
    traversor.traverse(doc);

    return formatter.toString().trim();
  }