Subject: | problem with SAX error handler |
hello
this error was already reported to the perl-xml mailing list
my system:
v5.6.1 built for i586-linux
Linux mjdev 2.4.10-4GB #1 Tue Sep 25 12:33:54 GMT 2001 i686 unknown
XML-SAX-Expat-0.30
XML-SAX-0.09
I have this xml file:
<?xml version="1.0"?>
<birds>
<family name="Eagles">
<species comment = "in germany only in the alpes">
<english_name>Golden Eagle</english_name>
<german_name>Steinadler</german_name>
<food>Birds, Mammals</food>
</species>
<species comment = "greatest eagle in Europe">
<english_name>White-tailed Eagle</english_name>
<german_name>Seeadler</german_name>
<food>Birds, Mammals, Fish</food>
</species>
</iifamily>
</birds>
this file is passed as ARGV[0] to my script sax.pl (the script is attached)
when I run the code in the attached perl file I get this error
before installing XML::Expat
found fatal errorEnd tag mismatch (iifamily != family) [Ln: 14, Col: 11]
after installing XML::Expat I get this
mismatched tag at line 14, column 3, byte 430 at /usr/lib/perl5/site_perl/5.6.1/i586-linux/XML/Parser.pm line 185
with XML::Expat it seems that the methods in my error handler are never called.
I think with XML-SAX the newest SAX-Implementation is always used and because XML::Expat is newer than the default it is used here (which is okay because someone at the mailing list said that XML::Expat would be the best choice)
regards
markus
#!/usr/bin/perl -w
use XML::SAX;
use XML::SAX::ParserFactory;
package MyHandler;
sub new {
my $type = shift;
return bless {}, $type;
}
sub start_element {
my ($self, $element) = @_;
print "Starting element $element->{Name}\n";
}
package MyErrorHandler;
sub new {
my $type = shift;
return bless {}, $type;
}
sub warning {
print "found warning";
}
sub error {
print " found error";
}
sub fatal_error {
print "found fatal error";
}
package main;
my $handler = MyHandler->new();
my $p = XML::SAX::ParserFactory->parser(ContentHandler => $handler);
$p->set_error_handler(MyErrorHandler->new);
$p->parse_uri($ARGV[0]);