10.2 Transforming XML 257
use XML::Parser;
$p = new XML::Parser(Handlers => { Start => \&start,
End => \&end,
Char => \&char });
print("
$p->parsefile($ARGV[0]);
print("
sub start {
$tag = $[1];
if ($tag eq "Weight") {
print("
$weightElement = 1;
}
}
sub char {
if ($weightElement) {
print($
}
}
sub end {
if ($weightElement) {
print("\n");
$weightElement = 0;
}
}
Program 10.25 Transforming XML content