One of the main reasons is just the flexibility of XML. And the flexibility of Perl.

Say, you have the following XML snippet:

<yada hello="world"></yada>
Now, say you get as output the following:
<yada hello="world"/>
The XML parser/generator functions did nothing wrong, since in XML context both snippets are the same. Well mostly, since most XML parsers are probably very slightly faster parsing the second representation.

Now take a look in the direction of Perl. You parse some XML data into a hash. Since hashes don't hold ordered data, the order of the output is not guaranteed. Depending on your XML file and how you use it, it might not matter anyway. Let's take a look at a slightly more complex example:

<bars> <bar beer="Moe's Best" bartender="Moe">Moe's</bar> <bar beer="Unnamed" bartender="Sam">Cheers</bar> </bars>
When you read it into a hash of hashes and write it out again, you might get:
<bars> <bar bartender="Sam" beer="Unnamed">Cheers</bar> <bar beer="Moe's Best" bartender="Moe">Moe's</bar> </bars>
This would still represent the same dataset. If order is important, you'll have to use arrays. XML::Simple has an option for that.

BREW /very/strong/coffee HTTP/1.1
Host: goodmorning.example.com

418 I'm a teapot

In reply to Re^2: XML::Simple problems by cavac
in thread XML::Simple problems by norricorp

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.