Java HTML to Text toElement(String html)

Here you can find the source of toElement(String html)

Description

Converts an HTML string to an HTML element.

License

Open Source License

Parameter

Parameter Description
html the HTML

Return

the HTML element

Declaration

public static Element toElement(String html) 

Method Source Code


//package com.java2s;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class Main {
    /**/*  w w  w .  ja  v  a  2  s  . c  o  m*/
     * Converts an HTML string to an HTML element.
     * @param html the HTML
     * @return the HTML element
     */
    public static Element toElement(String html) {
        return toElement(html, null);
    }

    /**
     * Converts an HTML string to an HTML element.
     * @param html the HTML
     * @param baseUrl the base URL
     * @return the HTML element
     */
    public static Element toElement(String html, String baseUrl) {
        Document d = (baseUrl == null) ? Jsoup.parse(html) : Jsoup.parse(html, baseUrl);
        return d.getElementsByTag("body").first().children().first();
    }
}

Related

  1. html2text(String html)
  2. html2text(String htmlStr)
  3. text(Element e)
  4. text(Element element)
  5. textOf(final Element el)
  6. toHtmlByHtml(String html)
  7. toHtmlByPlain(String plainText)