XML supports just a few entities, and nbsp
is certainly not one of them. To make your code running you should declare a meaning of your entites in DTD.
You can add following declaration to document:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
If you don't have any influence on a document, then you can use EntityResolver2
which provides interface for this.
See: EntityResolver2 - method getExternalSubset