From: Phrogz Date: 2007-12-11T12:28:24+09:00 Subject: Re: REXml help - Insert newlines into large xml file On Dec 10, 6:49 pm, Sean Nakasone wrote: > Hello, I have a large xml file that does not have any newlines in it. Can > someone please provide some code to use REXML to simply read in an xml, > insert newlines after the xml sections or elements, then spit it out to > stdout. This way I'd at least be able to open the xml file in an editor > so I can read what kind of format it has. I don't know anything about > REXML so it needs to be a somewhat complete script. thank you. irb(main):001:0> require 'rexml/document' irb(main):002:0> doc = REXML::Document.new( "" ) irb(main):003:0> doc.write $stdout => [, ... ] irb(main):004:0> doc.write $stdout, 0 You can use IO.read("somefile.xml") to read the contents into a single string. You can pass a file to the REXML::Document#write method instead of $stdout, e.g. File.open( "with_newlines.xml", "w" ){ |file| doc.write( file, 0 ) }