Java HTML Parse Jsoup removeAllHtmlTags(String unsafe)

Here you can find the source of removeAllHtmlTags(String unsafe)

Description

Remove all HTML tags from the given string

License

Apache License

Parameter

Parameter Description
unsafe unsafe

Return

sanitized string

Declaration

public static String removeAllHtmlTags(String unsafe) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.safety.Cleaner;
import org.jsoup.safety.Whitelist;

public class Main {
    /**/*from   ww w  . j  a  v a  2  s. com*/
     * Remove all HTML tags from the given string
     *
     * @param unsafe unsafe
     * @return sanitized string
     */
    public static String removeAllHtmlTags(String unsafe) {
        if (unsafe == null) {
            return null;
        } else {
            // Based on Jsoup.clean; the only difference is text() instead of html()
            Document dirty = Jsoup.parseBodyFragment(unsafe);
            Cleaner cleaner = new Cleaner(Whitelist.none());
            Document clean = cleaner.clean(dirty);
            return clean.body().text();
        }
    }
}

Related

  1. parseTemplate1_2(Element element)
  2. parseUTF8HTMLDocument(String html)
  3. parseWithAdultCheck(URL url, int timeout)
  4. prettyPrint(String html)
  5. processHtml(String html)
  6. removeHTMLTags(final String text)
  7. removeTag(String html)
  8. sanitizeHTML(String html)
  9. stripHTML(final String value)