Pathologically Eclectic Rubbish Lister | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
No module that aims to convert between XML and hashrefs does a good job. This is simply because the data model of XML is nothing like a hash. How do you represent this as a hash?
You either end up with a hopelessly complicated hash/array structure to represent it unambiguously:
... which is a nightmare to find stuff in. Or you do this:
... and stop caring about stuff like the distinction between attributes and elements and text nodes, the order of a node's children, etc... which means that when you start outputting XML, the XML you generate will confuse the hell out of any tools that consume it. Which is not to say that particular flavours of XML - e.g. RSS or Atom or OPML or blah or blah - cannot be usefully converted to a hash by a module that understands the schema. If you know that an Atom <entry> element can never validly have a title attribute, but will always have exactly one <title> element as a child, then representing that as:
... is fine. But modules like XML::Simple and its ilk don't target specific flavours of XML; they try to handle generic XML. Even the very best generic XML-to-hash module will be horribly broken, because the whole concept is horribly broken.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
In reply to Re^2: comments on xml 2 hash 2 xml using libXML
by tobyink
|
|