# ---------------------------------------------
use vars qw(%startsub, %endsub);
%startsub = (
"stock_quote" => "
",
"symbol" => "
",
"price" => "
Price:",
"date" => "
Date:",
"time" => "
Time:",
"change" => "
Change:",
"volume" => "
Volume:"
);
%endsub = (
"stock_quote" => "",
"symbol" => "
",
"price" => "",
"date" => "",
"time" => "",
"change" => "",
"volume" => ""
);
# ---------------------------------------------
use XML::Parser;
my $file = shift;
my $parser = new XML::Parser(ErrorContext => 2);
$parser->setHandlers(Start => \&start_handler,
End => \&end_handler,
Char => \&char_handler);
$parser->parsefile($file);
# ---------------------------------------------
#
# The handlers for the XML Parser.
#
sub start_handler
{
my $expat = shift; my $element = shift;
# element is the name of the tag
print $startsub{$element};
# Handle the attributes
while (@_) {
my $att = shift;
my $val = shift;
print "$att=$val ";
}
}
sub end_handler
{
my $expat = shift; my $element = shift;
print $endsub{$element};
}
sub char_handler
{
my ($p, $data) = @_;
print $data;
}