# REXML: insert an element as the first child

**URL:** <https://rubytalk.org/t/rexml-insert-an-element-as-the-first-child/13311>\
**Category:** ruby-talk\
**Created:** [29 August 2004 23:04 UTC](https://rubytalk.org/t/rexml-insert-an-element-as-the-first-child/13311 "2004-08-29T23:04:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koen\_Vervloesem](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@Koen\_Vervloesem](https://rubytalk.org/u/Koen_Vervloesem)\
**Post date:** [29 August 2004 23:04 UTC](https://rubytalk.org/t/rexml-insert-an-element-as-the-first-child/13311/1 "2004-08-29T23:04:12Z")

</div>

Hi,

In REXML I can add an element as a child to another element with the method add\_element. But it adds the element as the last child. Is there any way to add the element as the first child?

Regards,

Koen Vervloesem

> **···**
>
> --  
> "A man with a watch knows what time it is. A man with two watches is never sure." (Segal's Law)

---

<div class="post-metadata">

**Author:** ![Carlos](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@Carlos](https://rubytalk.org/u/Carlos)\
**Post date:** [31 August 2004 18:27 UTC](https://rubytalk.org/t/rexml-insert-an-element-as-the-first-child/13311/2 "2004-08-31T18:27:18Z")

</div>

[Koen Vervloesem \<koen.vervloesem@myrealbox.com\>, 2004-08-30 01.04 CEST]

> In REXML I can add an element as a child to another element with the  
> method add\_element. But it adds the element as the last child. Is there  
> any way to add the element as the first child?

See [ruby-talk:25119].

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/25119](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/25119)

Good luck.

---

<div class="post-metadata">

**Author:** ![Koen\_Vervloesem](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@Koen\_Vervloesem](https://rubytalk.org/u/Koen_Vervloesem)\
**Post date:** [31 August 2004 22:32 UTC](https://rubytalk.org/t/rexml-insert-an-element-as-the-first-child/13311/3 "2004-08-31T22:32:54Z")

</div>

> See [ruby-talk:25119].
> 
> [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/25119](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/25119)
> 
> Good luck.

Thanks. This helps a lot.

Koen
