# Prevent REXML from doing any character decoding

**URL:** <https://www.ruby-forum.com/t/prevent-rexml-from-doing-any-character-decoding/115193>\
**Category:** Ruby\
**Created:** [September 21, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/prevent-rexml-from-doing-any-character-decoding/115193 "2007-09-21T15:30:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [September 21, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/prevent-rexml-from-doing-any-character-decoding/115193/1 "2007-09-21T15:30:54Z")

</div>

How can I ask REXML to NOT DO any sort of character decoding or  
encoding when it processes XML files?  
My files include all sorts of encoding, which is unfortunately not  
recognized by REXML. I just want to process it so that all characters  
are maintained exactly as they are.

For example, Unicode HTML encoded characters (like &nbsp;) should just  
stay this sequence, and not transformed into Â.

It it possible?  
Can I do this without adding a character encoding line to the XML  
files?

Thanks,  
Helzer

---

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [September 21, 2007, 5:06pm UTC](https://www.ruby-forum.com/t/prevent-rexml-from-doing-any-character-decoding/115193/2 "2007-09-21T17:06:13Z")

</div>

On 9/21/07, helzer [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can I do this without adding a character encoding line to the XML  
> files?
> 
> Thanks,  
> Helzer

[http://www.germane-software.com/software/rexml/docs/tutorial.html](http://www.germane-software.com/software/rexml/docs/tutorial.html) :

There is a programmatic solution: :raw. If you set the :raw flag on  
any Text or Element node, the entities within that node will not be  
processed. This means that you’ll have to deal with entities yourself:

Entity Replacement

doc = Document.new(‘\<!DOCTYPE foo []\>replace  
&ent;’,{:raw=\>:all})  
doc.root.text #-\> “replace &ent;” doc.to\_s # Generates: #  
\<!DOCTYPE foo [ # #  
]\>replace &ent;
