xml file formatting from entire file in single string

Discussion in 'Ruby' started by David Southwell, Nov 3, 2009.

  1. 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
    David Southwell, Nov 3, 2009
    #1
    1. Advertising

  2. Jordi Bunster, Nov 3, 2009
    #2
    1. Advertising

  3. David Southwell

    Sven Schott Guest

    [Note: parts of this message were removed to make it a legal post.]

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

    http://tidy.rubyforge.org/

    On Wed, Nov 4, 2009 at 9:46 AM, David Southwell <>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
    >
    >
    Sven Schott, Nov 3, 2009
    #3
  4. David Southwell

    Phrogz Guest

    On Nov 3, 3:46 pm, David Southwell <> 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
    Phrogz, Nov 4, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan
    Replies:
    1
    Views:
    308
    Karl Seguin
    Oct 20, 2004
  2. Parvinder
    Replies:
    6
    Views:
    745
    Thomas G. Marshall
    Feb 27, 2005
  3. Crispy
    Replies:
    5
    Views:
    860
    e n | c k m a
    Aug 10, 2003
  4. Mothra
    Replies:
    10
    Views:
    474
    Anno Siegel
    Mar 11, 2005
  5. Replies:
    4
    Views:
    109
    Gunnar Hjalmarsson
    Jul 7, 2005
Loading...

Share This Page