I have to caution against XML::Simple, it is really only still useful for reading very simple XML files, and its output is often unreliable - exactly the issue you were asking about in the root node may pop up again later, and often in a way that you can't get rid of it with a configuration option. And I have to very strongly recommend against using that module for any kind of XML writing for the same reason. XML::Simple's own documentation recommends against its use (see the section "Status of this Module"), and see also XML::Simple needs to go!

I have successfully used XML::Rules as a replacement for XML::Simple several times, for example as I showed here. Once you get into how to configure it, you can produce data structures that look like the output of XML::Simple, but are much more robust (Update: their generation and layout, not the structures themselves). I have noticed that unfortunately the module is not perfect when writing/round-tripping XML files.

Although I haven't worked with it much myself, another module is XML::Compile, which is useful if you have an XML Schema for your XML. The module takes a little bit of setting up, but once it's working, AFAICT so far it seems to be quite reliable.

And in general there are lots of other good XML processing modules, for example XML::LibXML and XML::Twig are two good ones. The above two just help in producing Perl data structures similar to what XML::Simple does.


In reply to Re^2: hashref with(out) arrays by haukex
in thread hashref with(out) arrays by bfdi533

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.