Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Examples where XML::Simple is the optimal choice?

by Anonymous Monk
on Oct 23, 2015 at 09:15 UTC ( [id://1145734]=note: print w/replies, xml ) Need Help??


in reply to Examples where XML::Simple is the optimal choice?

XML::Rules obsoletes XML::Simple

If you don't feel like learning xpath or trees or twigs , if you feel hohaohoaoho...hashes of arrays and arrays of hashes ... are what you want then use XML::Rules

  • Comment on Re: Examples where XML::Simple is the optimal choice?

Replies are listed 'Best First'.
Re^2: Examples where XML::Simple is the optimal choice?
by Preceptor (Deacon) on Oct 23, 2015 at 09:23 UTC

    I would largely agree. I mean, XML::Twig has "simplify" which will likewise dump a data structure, which IMO means it also obseletes XML::Simple.

    What I'm trying to get to is - I'm feeling like I'm banging on saying "Just don't use XML::Simple, there are no good reasons to" and I'm after counter examples. Niches where it isn't just plain worse.

      What I'm trying to get to is - I'm feeling like I'm banging on saying "Just don't use XML::Simple, there are no good reasons to" and I'm after counter examples. Niches where it isn't just plain worse.

      You need to ask more noobs

      :) new things are scary, only noobs can come up with examples, because they like trying to write {foo}{bar} (but can't debug it)

      {foo}{bar} is better documented and more accessible to noobs than the others

      twig has too much documentation :D

      libxml docs don't teach you xpath or trees/dom or ...perlintro

      so they think "xml hash" and go searching .... after half hour of frustration they stumble upon XML::Simple

      Its why I try to give libxml examples often ... its 98% copy/paste

      Its also why I link threads where libxml/rules/simple/twig solutions are present....

      but even with all that compare/contrast, noobs like to inch through xml/hashes while simultaneously trying to learn perlintro

      they need handholding

      I used to :D

        Honestly though - What you get from XML::Simple isn't AT ALL simple. You need to set a bunch of (non default) options just to get something consistent out of it. Once you've done this, you end up with a daisy chain of array and hashes that you've no hope of navigating without referring to Data::Dumper.

        But yes, perhaps I need to ask more noobs, but they don't actually see the difference between a hacky bodge and some code that's just as efficient but way clearer.

        Actually, thinking about it - one of the fundamental problems here, is that the transformation between XML to has breaks down - because what you have in XML is:

        • Nodes beneath the same parent with the same name
        • Ordered named nodes
        • Attributes - which logically would be a hash, but if they do, they contend with children

        So with that in mind - you can craft XML that passes through XML::Simple painlessly by not doing any of those things:

        <xml> <element>value</element> <another_element>a different value</another_element> </xml>

        The irony is though - if your XML is that simple, then you didn't need XML::SImple either:

        my %stuff = $xml =~ m/(\w+)>([^<]+)</g;

        But as we know - it's a bad idea to parse XML with a regex - I think it's a bad idea to use XML::Simple for exactly the same reasons. (And you need to install it too)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1145734]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found