# Small issue with REXML output

**URL:** <https://www.ruby-forum.com/t/small-issue-with-rexml-output/50961>\
**Category:** Ruby\
**Created:** [December 23, 2005, 6:10am UTC](https://www.ruby-forum.com/t/small-issue-with-rexml-output/50961 "2005-12-23T06:10:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrislo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5e9695/32.png) [@chrislo](https://www.ruby-forum.com/u/chrislo)\
**Post date:** [December 23, 2005, 6:10am UTC](https://www.ruby-forum.com/t/small-issue-with-rexml-output/50961/1 "2005-12-23T06:10:50Z")

</div>

I’ve just started working with REXML recently and have encountered a  
small problem. After composing an XML document I want to output it to  
file, currently I’m using xmlDoc.write theFile, problem is, the  
resultant file does not have newlines after each element. When openning  
the file in a text editor it comes in as one big line.

Any idea how to inject newline characters without a bunch of post  
processing? Must be a pretty straightforward.

Thanks.  
Chris.

---

<div class="post-metadata">

**Author:** ![chrislo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5e9695/32.png) [@chrislo](https://www.ruby-forum.com/u/chrislo)\
**Post date:** [December 23, 2005, 6:28am UTC](https://www.ruby-forum.com/t/small-issue-with-rexml-output/50961/2 "2005-12-23T06:28:55Z")

</div>

On Fri, 23 Dec 2005, Chris L. wrote:

> I’ve just started working with REXML recently and have encountered a small  
> problem. After composing an XML document I want to output it to file,  
> currently I’m using xmlDoc.write theFile, problem is, the resultant file does  
> not have newlines after each element. When openning the file in a text  
> editor it comes in as one big line.
> 
> Any idea how to inject newline characters without a bunch of post processing?  
> Must be a pretty straightforward.

if you do that it will not longer be valid xml. try

puts doc.pretty

hth.

-a

---

<div class="post-metadata">

**Author:** ![chrislo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5e9695/32.png) [@chrislo](https://www.ruby-forum.com/u/chrislo)\
**Post date:** [December 23, 2005, 3:28pm UTC](https://www.ruby-forum.com/t/small-issue-with-rexml-output/50961/3 "2005-12-23T15:28:30Z")

</div>

Chris L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> I’ve just started working with REXML recently and have encountered a  
> small problem. After composing an XML document I want to output it to  
> file, currently I’m using xmlDoc.write theFile, problem is, the  
> resultant file does not have newlines after each element. When  
> openning the file in a text editor it comes in as one big line.

IIRC, there is an parameter to xmlDoc.write. Try xmlDoc.write(STDOUT,  
2).
