in reply to Re: problem in XML parsing
in thread problem in XML parsing

I don't like XML::Simple. Remove a team from the sample data and you get

Not an ARRAY reference at 675580.pl line 16.

Remove a player from ONE and you'll get

ONE Not an ARRAY reference at 675580.pl line 18.

The call to XMLin for this schema should be *at least*

my $teams = XMLin( $xml_text, ForceArray => [qw( football_team Player )], );

And then there's ForceContent.

XML::Simple is deceptively complex to use because it returns data in an unpredictable format, forcing you to use ref all over the place or to specify arguments to tell it what it already knows but chooses to destroy. All that because XML::Simple assumes attributes and elements are interchangeable. (Are they ever?)

Replies are listed 'Best First'.
Re^3: problem in XML parsing
by hipowls (Curate) on Mar 22, 2008 at 07:03 UTC

    Thanks for pointing out the potential problem with my code, I've updated the original post.

    I agree that XML::Simple isn't simple but at some point you have to provide a mapping between XML and perl data structures and nothing is truly simple. For reading XML without attributes it is good enough, though you do need to be aware of the traps (but that's what the man page and perlmonks are for;).

    For "real" XML processing I'd look elsewhere but this wasn't that question and then I'd be far more likely to seek advice than offer it.