Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Behaviour of parsed XML

by tobyink (Canon)
on Feb 26, 2020 at 18:18 UTC ( [id://11113451]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Behaviour of parsed XML
in thread Behaviour of parsed XML

It might solve this particular issue, but in general moving away from XML::Simple will serve you better long term. The module is conceptually broken. It treats XML as being basically weird-looking JSON. But XML's data model is entirely different than JSON's. Not going to get into a debate about which data model is better, but treating them the same is like writing flight-planning software that will only generate flight routes that follow highways.

Somebody else recommended XML::Rules, which is probably the easiest thing to transition to from XML::Simple. It still allows you to treat the XML like glorified JSON, but requires you to give it rules about how to translate between the models, with some sane defaults.

The other thing I'd recommend looking at is XML::LibXML, which provides a full DOM API for XML, which will be pretty familiar if you've done any client-side Javascript programming.

Replies are listed 'Best First'.
Re^4: Behaviour of parsed XML
by cavac (Parson) on Feb 28, 2020 at 14:35 UTC

    Well, that really depends on what you are trying to do. I'm using XML::Simple as my config parser for most of my projects reliably for over a decade.

    Would i use XML::Simple to work with Wikipedia exports? Heck no, that would be a major pain.

    Would i use XML::LibXML to parse a simple config file? Heck no, this would be total overkill and would waste a lot of developer time.

    The right tool for the right job. You know, TIMTOWTDI

    perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

      I hear you and in general I agree with you. However, in this specific case I will beg to differ. That's because in the synopsis for XML::Simple itself the author states:

      PLEASE DO NOT USE THIS MODULE IN NEW CODE.

      Those are his all-caps, not mine. Further in the STATUS OF THIS MODULE section he goes on to say

      The use of this module in new code is strongly discouraged.

      which again is his emphasis, not mine. Since he wrote the module he knows what he's talking about and I'm inclined to take him at his word. YMMV of course.

      If XML::Simple and XML::LibXML were the only options, I would agree with you, but they are not. It's like choosing between a plastic kids shovel and a hundred ton strip mine excavator when a short trip to the local Home Depot can get you a real shovel that works the same way but better than your plastic one.

      Please see Simpler than XML::Simple.

      Jenda
      1984 was supposed to be a warning,
      not a manual!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found