How to remove all inline styles and other attributes(class,onclick) from html elements using Jsoup?
Sample Input :
<div style="padding-top:25px;" onclick="javascript:alert('hi');">
This is a sample div <span class='sampleclass'> This is a sample span </span>
</div>
Sample Output :
<div>This is a sample div <span> This is a sample span </span> </div>
My Code (Is this is a right way or any other better approach is there?)
Document doc = Jsoup.parse(html);
Elements el = doc.getAllElements();
for (Element e : el) {
Attributes at = e.attributes();
for (Attribute a : at) {
e.removeAttr(a.getKey());
}
}