Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent JSOUP from unencoding attribute values

Tags:

jsoup

I have code, somewhat, like this

String str = "<element data=\"some &lt;data&gt;\"> &gt;foo&lt; </element>";

Document doc = Jsoup.parse(str, "", Parser.xmlParser());

But JSOUP unencodes data's value, producing something like this

<element value="some <data>">
  &gt;foo&lt;
</element>

How do I prevent JSOUP from unencoding attribute values?

like image 658
centerback Avatar asked Sep 28 '15 15:09

centerback


1 Answers

You're hitting a known issue of Jsoup (1.8.3 as of this writing).

See here for details: https://github.com/jhy/jsoup/issues/55

The issue has been posted on December 27 2010... nearly 5 years before your question. I hope the upvotes on it will help raising attention to it.

UPDATE
Jsoup author has closed the issue as WON'T FIX.

like image 83
Stephan Avatar answered Nov 15 '22 18:11

Stephan