When I parse XML and find a problem, I would like to tell where the problem is, i.e. at least print a line number. Here’s a complete little example:
use XML::SAX;
my $gFactory = XML::SAX::ParserFactory->new ();
my $gParser = $gFactory->parser (Handler => EventHandler->new ());
$gParser->parse_uri ("foo.xml");
exit 0;
package EventHandler;
use base 'XML::SAX::Base';
sub start_element {
my ($aSelf, $aElement) = @_;
my ($name, $attributes) = ($aElement->{Name}, $aElement->{Attributes});
print "at line/column/byte ...\n";
}
What would I use in the print statement?
I’ve searched the ‘net and found XML::SAX::DocumentLocator but am unsure if that’s what I’m looking for and if so, how to use it. Any gentle prodding in the right direction deeply appreciated!
PS: It appears the parser used under the hood is libxml.
JJ
I switched to using
XML::Parser::PerlSax. This module has a methodlocation()to return a hash with file, line, colum position that does the trick.See https://metacpan.org/pod/XML::Parser::PerlSAX