Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove CSS styling from text

I am getting HTML text from a web service. I removed the HTML by using following code, but CSS code is still there.

Code

TextView tvNews;
tvNews.setText(Html.fromHtml(extractContent));    
tvNews = (TextView) findViewById(R.id.tv_newsView);
tvNews.setText(Html.fromHtml(extractContent));

The above code removed the HTML, but CSS code is still there.

CSS Code

   <style>\nbody {\n    background-color: #ffffff;\n}\ntd\n{\npadding:5px;
\ncellpadding:25px;\n}\nthead th\n{\npadding:5px;\ncellpadding:25px;
\n}\n<\/style>\n<p><strong>My TEXT<\/strong> \u2013

Kindly guide me how to remove CSS code from feed and put it into textView

like image 431
dev90 Avatar asked Dec 05 '25 03:12

dev90


1 Answers

If you're looking for removing the html tags from html then use Jsoup( http://jsoup.org)

 String textFromHtml = Jsoup.parse(MY_HTML_STRING_HERE).text();
 TextView desc = (TextView) dialog.findViewById(R.id.description);
 desc.setText(textFromHtml);

or for WebView

You can use this jquery method to get only text

var myContent = '<div id="test">Hello <span>world!</span></div>';

alert($(myContent).text());

That results in hello world.

http://jsfiddle.net/D2tEf/ for an example

like image 183
Rahul Khurana Avatar answered Dec 07 '25 18:12

Rahul Khurana