# REXML Attributes and entities

**URL:** <https://www.ruby-forum.com/t/rexml-attributes-and-entities/112901>\
**Category:** Rails\
**Created:** [August 24, 2007, 9:48am UTC](https://www.ruby-forum.com/t/rexml-attributes-and-entities/112901 "2007-08-24T09:48:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gamecreature](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/958977/32.png) [@gamecreature](https://www.ruby-forum.com/u/gamecreature)\
**Post date:** [August 24, 2007, 9:48am UTC](https://www.ruby-forum.com/t/rexml-attributes-and-entities/112901/1 "2007-08-24T09:48:05Z")

</div>

Hi,

Maybe I’m missing something, but I’m trying to store a REXML Document  
to a string, loading it back later. Storing it again. etc…

I’ve noticed the following problem:

script/console session:

> > xml = REXML::Document.new("\<root value=" /\>") =\> … \</\>  
> > xml.to\_s =\> “\<root value=” /\>  
> > xml.root.attributes[‘value’] = ‘\<’  
> > xml.root.text = ‘\>’  
> > xml.to\_s =\> “\>” # fine by me, no problem…

> > xml2 = REXML::Document.new( xml.to\_s )  
> > xml2.to\_s =\> "\>

As you can see the root.text node is loaded back correctly…  
But the attribute root.attributes[‘value’] is synchronized  
incorrectly…

REXML version:

DATE = “2006/335”  
VERSION = “3.1.6”

Is this a bug?!?  
Does somebody have a solution for this?!?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![gamecreature](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/958977/32.png) [@gamecreature](https://www.ruby-forum.com/u/gamecreature)\
**Post date:** [August 24, 2007, 11:29pm UTC](https://www.ruby-forum.com/t/rexml-attributes-and-entities/112901/2 "2007-08-24T23:29:38Z")

</div>

I found my Windows Ruby on Rails REXML (1.8.4) installation is working  
perfectly. It seems a bug in the FreeBSD version which is REXML  
(1.8.6). I’m trying to submit a bug report to the REXML authors, but  
the server keeps timing out ☹

I also found the solution, there’s indeed a bug in REXML (1.8.6)

Change the code at line +/- 291 in text.rb: ( /usr/local/lib/ruby/1.8/  
rexml/text.rb )  
#copy = copy.gsub( EREFERENCE, ‘&’ )  
copy = copy.gsub( “&”, “&” )

To  
copy = copy.gsub( EREFERENCE, ‘&’ )  
#copy = copy.gsub( “&”, “&” )
