xml file formatting from entire file in single string

View: New views
4 Messages — Rating Filter:   Alert me  

xml file formatting from entire file in single string

by David Southwell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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


Re: xml file formatting from entire file in single string

by Jordi Bunster :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




Re: xml file formatting from entire file in single string

by Sven Schott :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

http://tidy.rubyforge.org/

On Wed, Nov 4, 2009 at 9:46 AM, David Southwell <david@...>wrote:

> 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
>
>

Re: xml file formatting from entire file in single string

by Phrogz-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov 3, 3:46 pm, David Southwell <da...@...> 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 "<root><foo bar='12'>yow</
foo></root>"
=> <UNDEFINED> ... </>

irb(main):003:0> doc.to_s
=> "<root><foo bar='12'>yow</foo></root>"

irb(main):004:0> doc.write( $stdout, 2 )
<root>
  <foo bar='12'>
    yow
  </foo>
</root>
=> [<?xml ... ?>, <root> ... </>]

irb(main):005:0> doc.write( $stdout, 4 )
<root>
    <foo bar='12'>
        yow
    </foo>
</root>
=> [<?xml ... ?>, <root> ... </>]

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