Hello Monks,
I'm fairly new to Perl and started recently to learn Perl to parse and work with XML files. Pretty neat and easy.
I'm currently using ::LibXML and having formatting problem. I am adding new node to an existing node using

$old_node->addChild($new_node);

worked fine but the formatting of each file is different for example my output would look something like:

<root_tag> <element1>text</element1> #space <element2>text</element2> #space <element3>txt</element3> <new_node> <new_element1>text</new_element1> <new_element2>text</new_element2><new_element3> </new_element3> </new_node> </root_tag>

in the above example my existing XML file has spaces between elements, where my new source file doesn't i.e <new_node>.
also the tags gets missed up when copied i.e <new_element2>text</new_element2><new_element3>
indentation is also not precise. Im outputting my results to a file using
$new_object->toString(2;);
$new_object->toFile('file_name.xml');
so in summary the question is whats the best way when using LibXML to get a nice formatted XML output.


In reply to XML output formatting by Anonymous Monk

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.