use 5.010;
use strict;
use warnings;
use XML::Parser;
my ($got_title, $in_title);
my $parser = XML::Parser->new(
Handlers => {
Start => sub { $in_title++ if $_[1] eq 'Title' },
End => sub { $in_title--, say "GOT TITLE: $got_title" if $_[1] eq 'Title' },
Char => sub { $got_title = $_[1] if $in_title },
},
);
$parser->parse(<<'XML');
Company A&B Information
Foo
Company X&Y Information
Bar
XML
####
use 5.010;
use strict;
use warnings;
use XML::Parser;
my (@got_title, $in_title);
my $parser = XML::Parser->new(
Handlers => {
Start => sub { $in_title++, @got_title = () if $_[1] eq 'Title' },
End => sub { $in_title--, say "GOT TITLE: @got_title" if $_[1] eq 'Title'; },
Char => sub { push @got_title, $_[1] if $in_title },
},
);
$parser->parse(<<'XML');
Company A&B Information
Foo
Company X&Y Information
Bar
XML