untitled

(ff) #1

240 10 Transforming with Traditional Programming Languages


use XML::Parser;

$p = new XML::Parser(Handlers => { Start => \&start,
End => \&end,
Char => \&char });
$p->parsefile($ARGV[0]);

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

Program 10.15 Parsing XML content

<Journal>
<ISSN>1083-7159</ISSN>
<JournalIssue>
<Volume>4</Volume>
<Issue>4</Issue>
<PubDate>
<Year>1999</Year>
</PubDate>
</JournalIssue>
</Journal>
<ArticleTitle>Breast cancer highlights.</ArticleTitle>
Free download pdf