# How to make REXML respect &nbsp; (in 1.9)

**URL:** <https://www.ruby-forum.com/t/how-to-make-rexml-respect-nbsp-in-1-9/152864>\
**Category:** Ruby\
**Created:** [November 8, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/how-to-make-rexml-respect-nbsp-in-1-9/152864 "2008-11-08T15:16:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [November 8, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/how-to-make-rexml-respect-nbsp-in-1-9/152864/1 "2008-11-08T15:16:16Z")

</div>

Rubies:

This fails on the second line…

```
REXML::Document.new('<b>&amp;</b>')
REXML::Document.new('<b>&nbsp;</b>')

```

…with Undeclared entity ’&nbsp;’

If I make that real XHTML, with a DOCTYPE and a html xmlns="…xhtml",  
it  
still fails.

I fixed the &nbsp; itself by adding [] to the DOCTYPE.  
This seems extremely tacky, because it disregards all the other fun  
stuff in  
XHTML.

(I suspect REXML with 1.8 did not have this issue.)

If I should call Entity.new(‘nbsp’, ’ '), I don’t understand how to .add  
that before the call to .new, and I don’t understand how to easily add  
new  
HTML content to a preexisting Document object.

Any tips?
