# Rexml - get raw xml of elements and text

**URL:** <https://www.ruby-forum.com/t/rexml-get-raw-xml-of-elements-and-text/50774>\
**Category:** Ruby\
**Created:** [December 21, 2005, 12:52am UTC](https://www.ruby-forum.com/t/rexml-get-raw-xml-of-elements-and-text/50774 "2005-12-21T00:52:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ammonc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58f4c7/32.png) [@ammonc](https://www.ruby-forum.com/u/ammonc)\
**Post date:** [December 21, 2005, 12:52am UTC](https://www.ruby-forum.com/t/rexml-get-raw-xml-of-elements-and-text/50774/1 "2005-12-21T00:52:37Z")

</div>

I’m aware that REXML’s Element class can give me the elements or the  
text  
(texts if there are many text elements between children elements). I  
want  
them both, and I want them in order, straight XML. (I’ve got some bold  
and  
italic tags there that are just for formatting)

---

<div class="post-metadata">

**Author:** ![ammonc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58f4c7/32.png) [@ammonc](https://www.ruby-forum.com/u/ammonc)\
**Post date:** [December 21, 2005, 1:01am UTC](https://www.ruby-forum.com/t/rexml-get-raw-xml-of-elements-and-text/50774/2 "2005-12-21T01:01:39Z")

</div>

Ammon C. wrote:

> I’m aware that REXML’s Element class can give me the elements or the text  
> (texts if there are many text elements between children elements). I want  
> them both, and I want them in order, straight XML. (I’ve got some bold and  
> italic tags there that are just for formatting)

to\_s ?

James

–

[http://www.ruby-doc.org](http://www.ruby-doc.org) - Ruby Help & Documentation  
[Ruby Code & Style](http://www.artima.com/rubycs/) - Ruby Code & Style: Writers wanted  
[http://www.rubystuff.com](http://www.rubystuff.com) - The Ruby Store for Ruby Stuff  
[http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys  
[http://www.30secondrule.com](http://www.30secondrule.com) - Building Better Tools

---

<div class="post-metadata">

**Author:** ![ammonc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58f4c7/32.png) [@ammonc](https://www.ruby-forum.com/u/ammonc)\
**Post date:** [December 22, 2005, 2:53pm UTC](https://www.ruby-forum.com/t/rexml-get-raw-xml-of-elements-and-text/50774/3 "2005-12-22T14:53:46Z")

</div>

On Dec 20, 2005, at 4:51 PM, Ammon C. wrote:

> I’m aware that REXML’s Element class can give me the elements or  
> the text  
> (texts if there are many text elements between children elements).  
> I want  
> them both, and I want them in order, straight XML. (I’ve got some  
> bold and  
> italic tags there that are just for formatting)

irb(main):001:0\> require ‘rexml/document’  
=\> true

irb(main):002:0\> d = REXML::Document.new( ‘Hello _there_  
world’ )  
=\> … \</\>

irb(main):003:0\> d.root.each\_child{ |n| p n }  
“Hello "  
 _… \</\>  
" world”  
=\> ["Hello “, … \</\>, " world”]_
