in reply to Re: XML::Simple: Loop through childnodes?
in thread XML::Simple: Loop through childnodes?
This is a bit problematic since if there ever was XML that'd contain only one <item> tag the structure would look different. With recent enough XML::Simple you can specify what tags to force to arrays$xml->XMLin("sample.xml",ForceArray => ['item']).
In case the XML starts to get bigger, it may be better to start using something different. XML::Twig or ... everyone guessed by now ... XML::Rules ;-)
use XML::Rules; my $parser = XML::Rules->new( rules => [ 'description,title' => 'content', 'item' => sub { print "$_[1]->{title}: $_[1]->{description}\n" return; }, 'inbox' => '', ], ); $parser->parse('sample.xml');
|
|---|