# Xml file formatting from entire file in single string

**URL:** <https://www.ruby-forum.com/t/xml-file-formatting-from-entire-file-in-single-string/178401>\
**Category:** Ruby\
**Created:** [November 3, 2009, 11:47pm UTC](https://www.ruby-forum.com/t/xml-file-formatting-from-entire-file-in-single-string/178401 "2009-11-03T23:47:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [November 3, 2009, 11:47pm UTC](https://www.ruby-forum.com/t/xml-file-formatting-from-entire-file-in-single-string/178401/1 "2009-11-03T23:47:05Z")

</div>

Hi

Anyone have or can point me to a snippet that will convert an entire xml  
file  
in the form of a continuous string into a well formatted file?

Thanks

David

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [November 4, 2009, 12:25am UTC](https://www.ruby-forum.com/t/xml-file-formatting-from-entire-file-in-single-string/178401/2 "2009-11-04T00:25:43Z")

</div>

I know it’s hardly a snippet but, tidy?

[http://tidy.rubyforge.org/](http://tidy.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [November 4, 2009, 6:00am UTC](https://www.ruby-forum.com/t/xml-file-formatting-from-entire-file-in-single-string/178401/3 "2009-11-04T06:00:31Z")

</div>

On Nov 3, 3:46 pm, David S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Anyone have or can point me to a snippet that will convert an entire xml file  
> in the form of a continuous string into a well formatted file?

Slim2:~ phrogz$ irb  
rirb(main):001:0\> require ‘rexml/document’  
=\> true

irb(main):002:0\> doc = REXML::Document.new “yow\</  
foo\>”  
=\> … \</\>

irb(main):003:0\> doc.to\_s  
=\> “yow”

irb(main):004:0\> doc.write( $stdout, 2 )  
  
  
yow  
  
  
=\> [\<?xml ... ?\>, … \</\>]

irb(main):005:0\> doc.write( $stdout, 4 )  
  
  
yow  
  
  
=\> [\<?xml ... ?\>, … \</\>]

For more, see:  
[http://www.germane-software.com/software/rexml/docs/tutorial.html](http://www.germane-software.com/software/rexml/docs/tutorial.html)
