Arts & Entertainment
...
...
...
...
####
$parser = XML::Parser->new(Handlers => {Start => \&start,
Char => \&char,
End => \&end}
);
sub start{
my ($p, $elt, %atts) = @_;
if ($elt eq 'Site') {
%site = (); #this is the hash per one site
}
if ($elt eq 'Id') { $tag_id = 1; }
if ($elt eq 'Title') { $tag_title = 1; }
}
sub char {
my ($p, $str) = @_;
if ($tag_id eq 1) {
$id = trim($str);
}
if ($tag_title eq 1) {
$title = trim($str);
}
}
sub end{
my ($p, $elt) = @_;
if ($tag_id eq 1 and $elt eq 'Id') {
$site{ $id } = $id;
$tag_id = 0;
}
if ($tag_title eq 1 and $elt eq 'Title') {
$site{ $title } = $title;
$tag_title = 0;
}
if ($elt eq 'Site') {
push(@cb, %site);
print %site . "\n";
}
}
# if I want to process now the @cb then no data are inside.