# REXML question

**URL:** <https://www.ruby-forum.com/t/rexml-question/74002>\
**Category:** Ruby\
**Created:** [October 29, 2006, 1:20am UTC](https://www.ruby-forum.com/t/rexml-question/74002 "2006-10-29T01:20:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pau\_Garcia\_i\_Quiles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@Pau\_Garcia\_i\_Quiles](https://www.ruby-forum.com/u/Pau_Garcia_i_Quiles)\
**Post date:** [October 29, 2006, 1:20am UTC](https://www.ruby-forum.com/t/rexml-question/74002/1 "2006-10-29T01:20:06Z")

</div>

Hello,

I am using REXML to create XML documents but I am facing a problem: I  
cannot  
add XML childs.

I want to create a parent element with REXML, then add a bunch of XML as  
a  
children (I already have that XML). I would like to do something like  
this:

xml = REXML::Element.new(‘parent’)  
xml.add\_xml\_element(‘value1value2’)

Then xml.to\_s would output:  
value1value2

I have tried with REXML::Element#add\_element, but it adds an extra ‘\<’  
before  
the child:  
\<value1value2

Am I trying something impossible?

Thank you.

---

<div class="post-metadata">

**Author:** ![Pau\_Garcia\_i\_Quiles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@Pau\_Garcia\_i\_Quiles](https://www.ruby-forum.com/u/Pau_Garcia_i_Quiles)\
**Post date:** [October 29, 2006, 9:20am UTC](https://www.ruby-forum.com/t/rexml-question/74002/2 "2006-10-29T09:20:35Z")

</div>

Pau Garcia i Quiles:

> xml = REXML::Element.new(‘parent’)  
> xml.add\_xml\_element(‘value1value2’)
> 
> Then xml.to\_s would output:  
> value1value2

# Â»ElementÂ« for creating tags:

parent = REXML::Element.new(‘parent’)

# Â»DocumentÂ« for XML input:

child = REXML::Document.new(‘value1’)

parent \<\< child  
parent.to\_s

Kalman
