# Uninitialized constant Hpricot::XChar

**URL:** <https://www.ruby-forum.com/t/uninitialized-constant-hpricot-xchar/148753>\
**Category:** Rails\
**Created:** [September 16, 2008, 8:43pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-hpricot-xchar/148753 "2008-09-16T20:43:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xavi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/8e8cbc/32.png) [@xavi](https://www.ruby-forum.com/u/xavi)\
**Post date:** [September 16, 2008, 8:43pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-hpricot-xchar/148753/1 "2008-09-16T20:43:44Z")

</div>

Hello,

I’m using Hpricot in a Rails app. I’m trying to modify how it parses  
non-breaking space entities (&nbsp;) so that they are converted into  
spaces when using Hpricot’s inner\_text (instead of being converted to  
the corresponding unicode code point). To do this, I am trying this…

Hpricot::XChar::PREDEFINED\_U.merge!({"&nbsp;" =\> 32})

as suggested in  
[http://code.whytheluckystiff.net/hpricot/ticket/137#comment:4](http://code.whytheluckystiff.net/hpricot/ticket/137#comment:4)

I’ve put that line at the beginning of the controller where I’m using  
Hpricot, and the problem is that when I try to run that code I get the  
error…

uninitialized constant Hpricot::XChar

Any idea about why this is happenning? I’m using Rails 2.1.0

Thanks in advance.

xavi

---

<div class="post-metadata">

**Author:** ![xavi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/8e8cbc/32.png) [@xavi](https://www.ruby-forum.com/u/xavi)\
**Post date:** [September 16, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-hpricot-xchar/148753/2 "2008-09-16T21:10:27Z")

</div>

I don’t know what could be causing that error but my suggestion would  
be that, if you can’t fix it, just modify the resulting string with  
gsub. That’s the best I can come up with.

On Sep 16, 8:43 pm, Xavi C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![xavi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/8e8cbc/32.png) [@xavi](https://www.ruby-forum.com/u/xavi)\
**Post date:** [September 17, 2008, 8:57am UTC](https://www.ruby-forum.com/t/uninitialized-constant-hpricot-xchar/148753/3 "2008-09-17T08:57:31Z")

</div>

XChar implementation seems to be replaced by “c” based implementation

Changing the above statement to Hpricot::PREDEFINED\_U.merge!({"&nbsp;"  
=\> 32}) seems to execute without errors. I didn’t had time to test it  
out…

---

<div class="post-metadata">

**Author:** ![xavi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/8e8cbc/32.png) [@xavi](https://www.ruby-forum.com/u/xavi)\
**Post date:** [September 17, 2008, 10:38am UTC](https://www.ruby-forum.com/t/uninitialized-constant-hpricot-xchar/148753/4 "2008-09-17T10:38:39Z")

</div>

arvind wrote:

> XChar implementation seems to be replaced by “c” based implementation
> 
> Changing the above statement to Hpricot::PREDEFINED\_U.merge!({"&nbsp;"  
> =\> 32}) seems to execute without errors. I didn’t had time to test it  
> out…

That worked!  
Thanks all for your help!

xavi
