I'm using Jsoup to parse and modify some HTML. In certain places, I want to add a non-breaking space entity ( ) to the HTML. I assumed I could do it as in this simplified example:
Element paragraph = someDocument.select("p").first();
paragraph.text("First sentence. Second sentence.");
But Jsoup turns my
into  
effectively encoding the ampersand itself. I guess my real question is: how can I manually write an ampersand character to the text of an Element
?
You are doing Element.text. If its html, use .html(String s) instead so, replace your code with
Element paragraph = someDocument.select("p").first();
paragraph.html("First sentence. Second sentence.");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With