Forum: Ruby Small issue with REXML output

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cfa884b53d70897f6cc06acb95ce3c7d?d=identicon&s=25 Chris Large (Guest)
on 2005-12-23 06:10
(Received via mailing list)
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.
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2005-12-23 06:28
(Received via mailing list)
On Fri, 23 Dec 2005, Chris Large 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
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 Christian Neukirchen (Guest)
on 2005-12-23 15:28
(Received via mailing list)
Chris Large <ChrisLarge@shaw.ca> 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).
This topic is locked and can not be replied to.