Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace a tag using jsoup

Tags:

html

jsoup

I want to replace all image tags with div tag. I am able to select all tags and I know that I have to use replaceWith. But I am unable to use it.

And if I use TextNode for replacing it with <div> </div> and it converts into &amp;lt;div&amp;gt; my div &amp;lt;/div&amp;gt;

I know &amp;lt; and &amp;gt; is for < and >

Please help me.

like image 989
Deepak Avatar asked Dec 06 '22 16:12

Deepak


1 Answers

I guess you are replacing with element.replaceWith(new TextNode("<div></div>"),"");?

A Textnode is for text and escapes content - thats why you see the HTML entities. You need to replace with a tag, so do something like element.replaceWith(new Element(Tag.valueOf("div"), ""));.

like image 86
Hauke Ingmar Schmidt Avatar answered Dec 21 '22 21:12

Hauke Ingmar Schmidt