2

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

dev90
  • 7,187
  • 15
  • 80
  • 153
  • have you solved your problem can you share please? – Tara Dec 15 '17 at 11:09
  • @WaleedAsim : Use `jsoup` library – dev90 Dec 15 '17 at 11:55
  • would you like to share? because i'm using Jsoup but didnt work in my recyclerView Adapter – Tara Dec 15 '17 at 11:58
  • @WaleedAsim : you can also do following; If you are using webview ; ` tvNews.loadDataWithBaseURL(null, "Your Data ", "text/html", "UTF-8", null); tvNews.getSettings().setJavaScriptEnabled(true);` – dev90 Dec 15 '17 at 12:35
  • i want to remove from html css from text not from webview. webview has loadDatawithBaseUrl method. its all about webView you wrote – Tara Dec 15 '17 at 12:41
  • @WaleedAsim : better to change you approach then. I am using web view – dev90 Dec 15 '17 at 12:46

1 Answers1

2

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

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60