in reply to xml confuse
oruse strict; use XML::Simple qw(XMLin); my $data = XMLin( $xml, ForceArray => [qw(Author)]); #use Data::Dumper; #print Dumper($data); foreach my $author (@{$data->{AuthorList}{Author}}) { print "$author->{ForeName} $author->{LastName}\n"; }
use strict; use XML::Rules; my $parser = XML::Rules->new( rules => [ _default => 'content', Author => 'as array', AuthorList => sub { return Authors => $_[1]->{Author} }, PubmedArticle => 'pass', ], stripspaces => 7, ); my $data = $parser->parse( $xml); use Data::Dumper; print Dumper($data); foreach my $author (@{$data->{Authors}}) { print "$author->{ForeName} $author->{LastName}\n"; }
The later is a bit more work, but lets you tweak the resulting datastructure to better fit your needs.
|
|---|