dear monks, after having found a lot of helpful information around the monastery, i just decided to join in here.
well, there is one thing i just came across and i'm really not sure if this is meant to be like this or if i am doing something wrong.

what i try to do is to write out some (also) human readable xml. this happens while i process/parse a stream of data, so i don't want to build up the whole xml structure (in a hash) and write it all out at once but do writes sequentially while data portions are processed.
to me, XML::Writer seems jsut to offer what i'm looking for.
since the output should be human readable and not come out as one long single line, i use the 'NEWLINES' arg on creation of my XML::Writer object.
somehow, the output is not quite as i expected; here is some sample:
use strict; use XML::Writer; use IO::File; my $output = new IO::File(">testout.xml"); my $writer = new XML::Writer(OUTPUT => $output, NEWLINES => 1); $writer->xmlDecl(); $writer->startTag("rootnode", "xmlns" => "my:name:space", "version" => + "1", "creator" => "anti"); $writer->emptyTag("emptynode", "value" => "abc"); $writer->startTag("node", "name" => "foo"); $writer->characters("Hello, world!"); $writer->endTag("node"); $writer->endTag("rootnode"); $writer->end(); $output->close();
in the putput-file (testout.xml) i find after running the above:
<?xml version="1.0"?> <rootnode xmlns="my:name:space" version="1" creator="anti" ><emptynode value="abc" /><node name="foo" >Hello, world!</node ></rootnode >
but i would prefer this to look like:
<?xml version="1.0"?> <rootnode xmlns="my:name:space" version="1" creator="anti"> <emptynode value="abc" /> <node name="foo"> Hello, world! </node> </rootnode>
indenting is useful but not as important as getting the lines wrapped nicely.
any ideas or suggestions?

thanks a lot in advance -- greetings, anti

edit: i'm using XML::Writer version 0.604; should be the latest...

In reply to newline behaviour with XML::Writer by antiplex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.