XHTML encode Android


I need to XHTML encode some text in Android.

I had been using Html.escapeHtml().

However Html.escapeHtml(" ") generates "  ". I need it to generate " &#160".

Is there an equivalent? I need like a Xhtml.escapeXhtml().

Or should I just do string replacements?


Ah, I just realized the problem is that the document is missing the DTD. I need to add

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   

to the top of the document

and then &nbsp; is valid.

Similar answer here: Undefined entity &nbsp XML parsing exception

Answered By – Kirby

Leave a Comment