XML-Simple reviews

cpanratings
 

RSS | Module Info | Add a review of XML-Simple

XML-Simple (2.20) *

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.)

Toby Inkster - 2013-05-23T02:53:24 (permalink)

2 out of 4 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.18) ****

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.

Jenda Krynicky - 2010-11-21T11:54:32 (permalink)

2 out of 3 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.18) *****

It's great. It lives up to its name and makes XML Simple. I love how configurable it is.
I read the (extensive) documentation once and started using it.

I worked with it a little, realized I didn't like the output but remembered an option for changing it... looked it up, and poof: beautiful, simple output.
Repeated for more options.

Currently using:
my $xmls = new XML::Simple(ForceArray => \@array_tags, KeyAttr => [], KeepRoot => 1, SuppressEmpty => '');

Randy Stauner - 2010-02-15T15:10:11 (permalink)

1 out of 1 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.18) ****

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);

Michael R. Davis - 2009-09-02T21:46:19 (permalink)

1 out of 1 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.18) ***

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.

Aristotle Pagaltzis - 2008-08-04T03:56:56 (permalink)

7 out of 10 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.18) *****

I have to disagree with Shlomi's downrating below.

This module does what it's designed to do and does it well.

Sure, it's not the Swiss-army-knife of XML parsing and formatting, but for any XML that *can* be represented as a perl data structure, this works.

The documentation describes how to force it to return arrays when normally it wouldn't.

As for saying that XML was *designed* to allow markup inside text, then no: that would be where you'd use a CDATA node, not a text node.

Rick Measham - 2008-08-03T19:57:00 (permalink)

1 out of 3 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.18) *****

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.

Zoffix Znet - 2008-08-03T19:44:38 (permalink)

2 out of 3 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.18) *

This module is an abomination. XML was not meant to be represented as a Perl 5 data structure in the way XML-Simple does. It should be named XML-Evil instead.

XML-Simple:

1. Sometimes uses arrays and sometimes uses hashes. How it decides that is inconsistent and error-prone.

2. Doesn't always generate identical XML when reading and writing.

3. Doesn't handle <p>Some <b href="url.tld/">markup</b>; inside text</p> properly, which is what XML is all about, and its key differentiator from YAML/JSON/etc.

4. Has many quirks and does not scale well.

---------------

I have a policy against helping people with XML problems. If you're looking for a good XML processing module look at XML::LibXML along with XPath, and possibly XML::LibXSLT.

Shlomi Fish - 2008-08-03T04:33:54 (permalink)

4 out of 13 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.18) *****

Original review: Very handy!

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.

Darren Kulp - 2008-07-24T08:56:46 (permalink)

4 out of 11 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.16) ****

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.

Franz Fasching - 2007-03-07T04:24:04 (permalink)

6 out of 6 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.14) ****

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.

--
Jedaï

Chaddaï Fouché - 2006-07-12T10:32:26 (permalink)

8 out of 9 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.14) *****

Highly recommended for turning XML into perl and vice versa.

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!

Lee Goddard - 2006-07-03T06:18:08 (permalink)

6 out of 7 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.12) *****

Helped me soup up a parser for our dependncy format to feed that
into visualizing app. Really easy to use, well documented, and
has the simplest interface there is.

blackc - 2004-09-19T00:28:32 (permalink)

1 out of 1 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.12) *****

Brilliant! A great example of why I like perl so much, straight forward, simple yet powerful way to read xml. Beats all that messing about with childnodes and so on.

matthewlock - 2004-04-30T21:54:40 (permalink)

2 out of 2 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.11) *****

just works fine and is easy to use !

cheno - 2004-03-05T15:10:06 (permalink)

1 out of 1 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.09) *****

great module! provides a super convenient interface to working with a XML file. invaluable!

ssmallen - 2004-02-26T02:42:56 (permalink)

1 out of 1 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.09) *****

Simple to use. Documentation clear and easy to understand. Very useful module.

phillhw - 2004-02-11T04:00:40 (permalink)

1 out of 1 found this review helpful. Was this review helpful to you?  Yes No

XML-Simple (2.09) *****

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.

Todd Caine - 2003-09-09T08:59:15 (permalink)

1 out of 1 found this review helpful. Was this review helpful to you?  Yes No