in reply to Re: comments on xml 2 hash 2 xml using libXML
in thread comments on xml 2 hash 2 xml using libXML
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?
<root toot="1"> 2 <toot>3</toot> 4 <toot>5</toot> 6 </root>
You either end up with a hopelessly complicated hash/array structure to represent it unambiguously:
{ root => { attributes => { toot => 1, }, contents => [ 2, { toot => { contents => [3] } }, 4, { toot => { contents => [5] } }, 6 ], } }
... which is a nightmare to find stuff in. Or you do this:
{ name => "root", toot => [1,3,5], text => [2,4,6], }
... 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:
my $entry = { title => "...", ..., };
... 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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: comments on xml 2 hash 2 xml using libXML
by space_monk (Chaplain) on Mar 18, 2013 at 17:26 UTC |