It is a feature. As JavaFan mentioned before, adding whitespace is a bit risky, as you have to make sure that it is non-significant. So xml_pp adds line returns and indentation in-between tags if there is no other data in the element. This is not guaranteed to be perfectly safe, but as in general the DTD is unavailable, that's about the best it can do. As soon as there is non-whitespace data in the element, then no indentation is added. Because according to the XML spec, in that case the whitespaces ARE significant.

It would be possible to add extra options to control more precisely the behavior of xml_pp, but that would be quite tricky, and error prone. At this point it's easier to write a custom pretty printer for your data. At least it's easier for me! ;--)


In reply to Re^2: Beautifying some SGML? (XML) by mirod
in thread Beautifying some SGML? by markww

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.