untitled

(ff) #1

10.2 Transforming XML 257


use XML::Parser;


$p = new XML::Parser(Handlers => { Start => \&start,
End => \&end,
Char => \&char });


print("\n");
$p->parsefile($ARGV[0]);
print("
\n");


sub start {
$tag = $[1];
if ($tag eq "Weight") {
print(" ");
$weightElement = 1;
}
}
sub char {
if ($weightElement) {
print($
[1]);
}
}
sub end {
if ($weightElement) {
print("\n");
$weightElement = 0;
}
}


Program 10.25 Transforming XML content
Free download pdf