This is why XML::Simple is anything but simple. Given:
use XML::Simple; use Data::Dumper; print Dumper XMLin do { local $/ = <DATA> }; __DATA__ <log> <entry> <date>2012-01-08</date> <text>Test</text> </entry> <entry> <date>2012-01-09</date> <text>Test</text> <text>Additional information</text> </entry> </log>
... as you can see, for each entry, the value for the "text" key is sometimes a string and sometimes an arrayref. You need to either test the value of "text" with ref to see if it's an arrayref, or pass additional options to XMLin to force it to always be an array. Once you've got a few potentially duplicable elements, this really starts to eliminate the supposed simplicity of XML::Simple.
Better to start straight out with something like XML::LibXML, which might present a more complicated API to begin with, it's at least consistent. Even if your XML gets more complex, your script doesn't have to.
In reply to Re: XML parsing
by tobyink
in thread XML parsing
by asa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |