Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: XML::Simple needs to go!

by Preceptor (Deacon)
on Dec 22, 2015 at 10:56 UTC ( [id://1150944]=note: print w/replies, xml ) Need Help??


in reply to Re: XML::Simple needs to go!
in thread XML::Simple needs to go!

Perhaps true. It is used in a load of places where it's overkill. It's effectively a data structure with an extra 'dimension' at each level - a node has:

  • content
  • child elements
  • attributes

XML is about the only way you can easily do all three at once, but ... how often is this necessary? XHTML type documents is perhaps the example I can think of - and that's a pretty big use case - but actually most uses the looser HTML spec rather than XML. (Major difference is - XML is much stricter about tags, ordering/closing/nesting). That's why I think XML is here to stay, but would generally agree with your assertion - most use cases I've seen it JSON is the better choice for data object transfer (API) and YAML for flat file (config).

But either way - once you have things like xpath and 'directory style' navigation (parent/child/sibling) of your XML doc, it is a lot saner. Certainly more so than trying to flatten part of it's dimensionality into a less complicated data structure like the perl native ones.

Replies are listed 'Best First'.
Re^3: XML::Simple needs to go!
by Laurent_R (Canon) on Dec 22, 2015 at 21:58 UTC
    Yes, I agree with you and, of course, my post was only half serious.

    The main reason for my frustration about XML is that I relatively frequently have to fix incoming data to make it valid XML before I can process it with a state-of-the-art parser. And that is a nuisance especially in view of the fact that this incoming data is in fact simple enough not to require any of the XML heavy artillery.

Re^3: XML::Simple needs to go!
by mr_mischief (Monsignor) on Jan 07, 2016 at 17:22 UTC

    Nested hashes and arrays could be forced into all three, albeit perhaps at the expense of some awkwardness. After all, it's all structured data. Below is just a quick example and I'm not writing this node to promote writing code to support this data structure. It's certainly not impossible, though, to denote these things.:

    my %data = ( 'attributes' => { '_name' => 'mydata', 'height' => 50, 'width' => '80%', }, 'children' => [ { 'attributes' => { '_name' => 'bob', ...} ...}, { 'attributes' => { '_name' => 'tom', ...} ...}, ], 'content' => 'yadda yadda ...', );

    Whether that's something you'd want to process later is another issue. Some people like to put a lot of predetermined information about their data into their code. Others like to keep the data as self-describing as possible and keep the code very general to work with that. There are strengths and weaknesses to either approach.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-28 14:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found