How to replace tag using jsoup

I want to replace all image tags with a div tag. I can select all the tags, and I know that I need to use replaceWith . But I can’t use it.

And if I use TextNode to replace it with <div> </div> and it converts to &amp;lt;div&amp;gt; my div &amp;lt;/div&amp;gt; &amp;lt;div&amp;gt; my div &amp;lt;/div&amp;gt;

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

Please help me.

+4
source share
1 answer

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

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

+11
source

Source: https://habr.com/ru/post/1393026/


All Articles