You are viewing a plain text version of this content. The canonical link for it is here.
Posted to p-dev@xerces.apache.org by Forrest Cahoon <Fo...@merrillcorp.com> on 2003/12/03 20:06:35 UTC

Schema validation: getting all the errors

Hello!

I've got XML::Xerces 2.3.0-2 from the ppm available at xml.apache.org and I'm using to validate documents against an external schema.

This simple code seems to work fine:

#!/usr/bin/perl -w
use strict;
use XML::Xerces;

die "Usage: $0 <xml document name> <schema name>\n" unless
  defined $ARGV[0] && -f $ARGV[0] && defined $ARGV[1] && -f $ARGV[1];

my $parser = XML::Xerces::XercesDOMParser->new;
$parser->setValidationScheme($XML::Xerces::AbstractDOMParser::Val_Always);
$parser->setDoNamespaces(1);
$parser->setCreateEntityReferenceNodes(1);
$parser->setDoSchema(1);
$parser->setExternalNoNamespaceSchemaLocation($ARGV[1]);
$parser->setExitOnFirstFatalError(0);
$parser->setValidationConstraintFatal(0);

my $error_handler = XML::Xerces::PerlErrorHandler->new();
$parser->setErrorHandler($error_handler);

eval {
  $parser->parse($ARGV[0]);
};
XML::Xerces::error($@) if ($@);

__END__

This program exits at the first schema error, though, and I want to get a report of all the errors.  I found a post to the xerces-c list which suggests that reporting all the errors is the default (http://nagoya.apache.org/eyebrowse/ReadMsg?listId=81&msgNo=5366) so it seems like there's at least hope I could get this behavior.

I would be very happy if anyone could offer advice on how I might get this to work.

Forrest Cahoon

not speaking for merrill corporation


Re: Schema validation: getting all the errors

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Forrest Cahoon" <Fo...@merrillcorp.com> writes:

> I've got XML::Xerces 2.3.0-2 from the ppm available at
> xml.apache.org and I'm using to validate documents against an
> external schema.

Good! You should really thank Martin for providing the PPM - it's the
first time that we've had a reliable use of Xerces on Windows.

> This program exits at the first schema error, though, and I want to
> get a report of all the errors.  I found a post to the xerces-c list
> which suggests that reporting all the errors is the default
> (http://nagoya.apache.org/eyebrowse/ReadMsg?listId=81&msgNo=5366) so
> it seems like there's at least hope I could get this behavior.
>
> I would be very happy if anyone could offer advice on how I might
> get this to work.

If you look at the samples/validator.pl example you will see how to do
this. 

Cheers,
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org