RE: Schema validation: getting all the errors

"Forrest Cahoon" <[email protected]>
Newsgroups gmane.text.xml.xerces-p.devel
Message-ID <[email protected]>
 
Jason E. Stewart wrote:

> "Forrest Cahoon" <[email protected]> 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.
> [ ... ]
> > This program exits at the first schema error, though, and I want to 
> > get a report of all the errors.  [ ... ]
> 
> If you look at the samples/validator.pl example you will see how to do this. 

Ok, I got the validator.pl sample (from 
http://svn.apache.org/repos/asf/xml/xerces-p/trunk/samples/validator.pl) 
but it requires that the schema be specified in the xml document being validated;
I need to be able to specify a schema in my code.

I've been working from the xerces-c examples at
http://xml.apache.org/xerces-c/schema.html#associate but I'm having trouble converting these to perl.

I tried using SAX first (as validator.pl does) but I couldn't figure out how to call setProperty to associate my external (no namespace) schema with the parser.
I tried this:

#!/usr/bin/perl -w

use XML::Xerces;
use strict;

my $parser = XML::Xerces::XMLReaderFactory::createXMLReader();
my $schema = "ownership3Document.xsd.xml";


$parser->setFeature("$XML::Xerces::XMLUni::fgSAX2CoreNameSpaces", 1);
$parser->setFeature("$XML::Xerces::XMLUni::fgXercesSchema", 1);
$parser->setFeature("$XML::Xerces::XMLUni::fgSAX2CoreValidation", 1);
$parser->setFeature("$XML::Xerces::XMLUni::fgXercesDynamic", 0);
$parser->setFeature("$XML::Xerces::XMLUni::fgXercesSchema", 1);
$parser->setProperty(
     "XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation",
                     $schema);

$parser->parse(XML::Xerces::LocalFileInputSource->new("doc3.xml"));


but that gives me the error

Type error in argument 3 of SAX2XMLReader_setProperty. Expected _p_void at
xerces_test.pl line 15.

I've tried many variations on this theme, but nothing seems to work.  That's when I decided to try the DOM parser and was able to set the schema with no problem (using $parser->setExternalNoNamespaceSchemaLocation).  It's my DOM parser which dies after it hits the first error.

So I need to either figure out how to set my schema in the SAX version, or get it to not die on the first error in the DOM version.

Any ideas?

Forrest Cahoon
not speaking for merrill corporation
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.