untitled

(ff) #1

242 10 Transforming with Traditional Programming Languages


use XML::Parser;

$p = new XML::Parser(Handlers => { Start => \&start,
Char => \&char });
$p->parsefile(’pubmed.xml’);

sub clear {
$pmidElement = 0;
$titleElement = 0;
$descElement = 0;
}
sub start {
if ($_[1] eq "PMID") {
$pmidElement = 1;
} elsif ($_[1] eq "ArticleTitle") {
$titleElement = 1;
} elsif ($_[1] eq "DescriptorName") {
$descElement = 1;
}
}
sub char {
if ($pmidElement) {
print("PubMed ID: $_[1]\n");
} elsif ($titleElement) {
print("Title: $_[1]\n");
} elsif ($descElement) {
print("Descriptor: $_[1]\n");
}
clear;
}

Program 10.16 Parsing PubMed citations
Free download pdf