friend's I have to parse the description from url,where parsed content have few html tags,so how can I convert it to plain text.
You can show HTML tags as plain text in HTML on a website or webpage by replacing < with < or &60; and > with > or &62; on each HTML tag that you want to be visible. Ordinarily, HTML tags are not visible to the reader on the browser.
Just call the method html2text with passing the html text and it will return plain text.
Yes, Jsoup will be the better option. Just do like below to convert the whole HTML text to plain text.
String plainText= Jsoup.parse(yout_html_text).text();
Just getting rid of HTML tags is simple:
// replace all occurrences of one or more HTML tags with optional // whitespace inbetween with a single space character String strippedText = htmlText.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", " ");
But unfortunately the requirements are never that simple:
Usually, <p>
and <div>
elements need a separate handling, there may be cdata blocks with >
characters (e.g. javascript) that mess up the regex etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With