# Inserting raw xml into a rexml document

**URL:** <https://www.ruby-forum.com/t/inserting-raw-xml-into-a-rexml-document/49966>\
**Category:** Ruby\
**Created:** [December 11, 2005, 6:03am UTC](https://www.ruby-forum.com/t/inserting-raw-xml-into-a-rexml-document/49966 "2005-12-11T06:03:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [December 11, 2005, 6:03am UTC](https://www.ruby-forum.com/t/inserting-raw-xml-into-a-rexml-document/49966/1 "2005-12-11T06:03:13Z")

</div>

how can i do this:

[ahoward@localhost xhtml-0.0.0]$ irb -r rexml/document  
irb(main):001:0\> REXML::Text::new("",  
respect\_whitespace=false, parent=nil, raw=false).to\_s  
=\> “\<foobar\>”

irb(main):002:0\> REXML::Text::new("",  
respect\_whitespace=false, parent=nil, raw=nil).to\_s  
=\> “\<foobar\>”

irb(main):003:0\> REXML::Text::new("",  
respect\_whitespace=false, parent=nil, raw=true).to\_s  
/usr/local/lib/ruby/1.8/rexml/text.rb:90:in `initialize': Illegal character '<' in raw string "<foobar>" (Exception) from (irb):3:in`new’  
from (irb):3:in `irb_binding' from /usr/local/lib/ruby/1.8/irb/workspace.rb:52:in`irb\_binding’  
from /usr/local/lib/ruby/1.8/irb/workspace.rb:52

is there no way to subvert the call to allow placing raw strings  
containing  
**any** chars into the output?

regards.

-a

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [December 11, 2005, 7:43am UTC](https://www.ruby-forum.com/t/inserting-raw-xml-into-a-rexml-document/49966/2 "2005-12-11T07:43:05Z")

</div>

On 2005.12.11 14:00, “Ara.T.Howard” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> =\> “\<foobar\>”  
> **any** chars into the output?  
> Are you actually trying to create new elements in the doc? (If not, then  
> the entity conversion is the correct behaviour.) If you want to insert  
> elements, the simplest way is probably to just create a new document  
> from the string and then insert that as a child of your current  
> element.

> regards.
> 
> -a

E

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [December 11, 2005, 8:19am UTC](https://www.ruby-forum.com/t/inserting-raw-xml-into-a-rexml-document/49966/3 "2005-12-11T08:19:38Z")

</div>

On Sun, 11 Dec 2005, Eero S. wrote:

> Are you actually trying to create new elements in the doc? (If not, then the  
> entity conversion is the correct behaviour.) If you want to insert elements,  
> the simplest way is probably to just create a new document from the string  
> and then insert that as a child of your current element.

that’s just what i did! thanks!

-a
