newPerlr has asked for the wisdom of the Perl Monks concerning the following question:

using XML Writer i wrote a programme that reads a log file and creates a XML output accordingly but then i found out the XML output is not intended. it seems like the whole XML is in one line. when i open the XML in a web browser it comes fine but when i open it text editors everything comes as a mess. is there any way to intend or at lest break to new line after every tag???

i tried 'NEWLINES => 1' but it brakes the line before the close angle bracket '>' thank you in advance

Replies are listed 'Best First'.
Re: XML Writer indentation
by samtregar (Abbot) on Dec 05, 2008 at 18:27 UTC
    The xml_pp script that comes with XML::Twig does exactly this.

    -sam

Re: XML Writer indentation
by jeffa (Bishop) on Dec 05, 2008 at 21:29 UTC

    I finally gave up on XML::Writer and switched to XML::Generator. Not only does it give you a Perl-ish interface (Writer is sooo Java) -- it actually formats your XML output in ways you want. 8)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      I found a super simple solution here:

      http://blog.namran.net/2011/01/22/xml-beautify-using-perl-xmlwriter/

      Basically, what one needs is this:

      my $writer = new XML::Writer ( OUTPUT => \$xml, DATA_MODE => 1,DATA_INDENT => 2 );
Re: XML Writer indentation
by Anonymous Monk on Dec 05, 2008 at 09:08 UTC
    Get a better text editor ... search documentation for "indent" (DATA_MODE,DATA_INDENT).