For any XML work where any of the following is true, XML::Simple is not your friend:

* The order of elements is important.

* The distinction between an element and an attribute is important.

* You want to preserve comments.

* You want to preserve whitespace.

* Some elements have mixed content (i.e. an element which contains some text data mixed in with child elements)

* You need to support namespaces

It's not that there's anything wrong with XML-Simple's implementation; the problem is with the entire concept of mapping between arbitrary XML and plain nested hashes/arrays.

An XML element is conceptually something like the simultaneous combination of a scalar string (the element name), a hash (the element's attributes and their values), and an array (the element's contents). You could model it like that with an overloaded object, but that approach doesn't seem to have caught on.

Something like XML-Rules, which is designed to be configured for a particular flavour of XML first, will provide a reasonable solution to map between XML and plain nested hashes/arrays, for some flavours of XML. (It's mostly suitable for data-centric XML rather than document-centric; think Atom, but not XHTML.)

Other than that, using a generic DOM or event-driven XML tool (like XML-LibXML or XML-Twig) will save you pain in the long term.

XML-Simple's simplicity might lure you in, but can end up causing you problems and confusion later on. (In fairness to the module's author, he does note XML-Simple's limitations in the pod.)

I like to get a plain old data-structure out of the XML, the catch with XML:Simple is that the datastructure is either not consistent or too complicated. The ForceArray and other options go a long way to that goal, but not far enough. For example tags with optional attributes still cause problems.
You may have a look at perlmonks.org/?node_id=697036 to see an alternative.

I love XML-Simple. As a "data person", you just can't get better. I do always have to tweak the parameters and usually use ForceArray=>1. Typically, I construct with something like XML::Simple->new(XMLDecl=>1, RootName=>q{document}, ForceArray=>1);

Shlomiâ€™s criticism is spot-on in several ways, though I wouldnâ€™t go so far as to rate this module a single star. Of the problems he noted, at least inconsistent mapping to Perl data structures and inept handling of mixed content are in fact troublesome.

With sufficient experience or study of the documentation you can configure the module so that it will produce data structures that do not surprise you (or your code!), but then either the module interface or the resultant data structures can no longer be considered â€œsimple.â€ If you do the simplest possible thing that can give you consistent data structures, then you will have to deal with an extra level of indirection in your Perl data structure for every level of nesting in the XML. If you want to have more convenient Perl data structures than that, you need to spend quite some time until you have XML::Simple configured *just so* for the XML vocabulary in question.

Shlomi is further correct that mixed content is what XML is all about. If your data is so regular that it can be mapped directly to a data structure, then JSON or the Config::General format or something of the sort are all much better options than XML.

All that said, this module is very useful for one-off data diving jobs. When you run into a pile of XML and you merely want to get in, pull something out of it, and get out, and never do it again, this module is quite likely to be the fastest road to success. You will often not even have to care about any botched mixed content, so in that kind of situation that is not a problem either.

But before you start building elaborate setups of XML::Simple configuration options to make your data structure map less painfully to Perl data structures, you should instead invest your time into learning XPath, for which you will be richly rewarded in convenience. Surfing an XML document with XPath expressions is much more concise than navigating a Perl data structure derived from the same XML document, particularly if you want to deal with sets of leaf nodes under sets of parent elements. That is the simplest case in XPath and will simply return a list of all the leaf nodes. In Perl, you need to nest another loop for every level at which you deal with a set.

Overall, 3 stars from me. It does what it says on the tin, and sometimes itâ€™s just what you need, but itâ€™s of limited use and the API has grown astonishingly complex in trying to be all things to all people.

Despite the previous comment I rate this distro to max.. it does what it was made for.. haven't failed me so far. I like the "press button - receive bacon" interface. As for "sometimes hashes - sometimes arrayrefs" this can be configured. Read the documentation.

OK, that was a useless review. Really, though, XML::Simple, though not general-purpose, has saved me so much time and has done The Right Thing so many times that I could hardly imagine coding without it.

Excellent and easy to use module. It probably should be better named XML::Config or something like that due to its original purpose of parsing XML config files. Either that, or make the options "KeepRoot => 1" and "KeyAttr => []" the default for parsing generic XML files, otherwise users searching for a simple generic XML parser will get confused by the resulting PERL data structure.
Overall a simple and handy module that is fun to use.

I gave this module a good rating since I think you can use it efficiently to dig some information from a xml document in a few lines, however I believe this module is ill-named : compare to a LWP::Simple for example, XML::Simple is much harder to use for a beginner, I would even say it's harder than most of the others XML processing module :

Since the module isn't strict in its structure building, it's easy to get subtle bugs which don't appear with all documents but only on specific instance (e.g. an element that appears most frequently in a list will normally be put in an array, but if it appears alone once, it will not be put in an array, you need to specifically say to XML::Simple you always want this element in an array... to a beginner who check on 2 or 3 examples this can easily bite him !).
This module allows for the most compact xml parsing and accessing among the XML modules (in some case) but not for the most simple, thus it should probably be renamed to something more appropriate (XML::CompactAddressing ? XML::Concise ?) and be advertised for its conciseness, not for its simplicity.

All aspects are highly configurable, although the default interface is so well configured you may not need to configure any further. If you do, the POD is clear and detailed (a rara combination).

The author is great: quick to respond, quick to fix bugs, and polite when pointing out operator error.

The only thing it lacks is support for "mixed content" XML, that is XML where elements contain both text nodes and other elemeents. As the author says in the POD, if it supported mixed content, it'd not be Simple!

I use this module all the time for simple configuration files. It's very handy to be able to transform XML to a Perl data structure and vice versa. It doesn't get much easier than the XMLin() and XMLout() subroutines.