You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Christer Lindqvist <ch...@carill.se> on 2002/01/17 16:09:59 UTC

Failing to validate using schema

Hi,


I'm having trouble getting schema validation to work properly with 1.6.0;
depending on whether I use a validating SAX- or DOMParser, I get different
(erroneous) outcomes. It should be noted that I've just recently started
using the Xerces C++, but have failed to find any help on the following.
(My apologies if issues like this are dealt with in an FAQ I've overlooked.)

Here's the thing ('parser' being the DOMParser ref., saxParser
the....SAXParser!):

-----------------------------------
 try
  {
    parser->setDoSchema(true);
    parser->setValidationScheme(DOMParser::Val_Auto);

parser->setExternalSchemaLocation("file:///C:/projekt/GPS/GDL/xerces/gdlsche
ma.xsd");
    parser->setValidationSchemaFullChecking(true);		//These properties being
set, you'd think it would work!
    parser->setValidationConstraintFatal(true);
    parser->setExitOnFirstFatalError(true);
    parser->setIncludeIgnorableWhitespace(false);
    parser->setErrorHandler(new GDLErrorHandler);    //The handler just
throws the exception right back at caller..

    parser->reset();


    saxParser->setDoSchema(true);
    saxParser->setValidationScheme(SAXParser::Val_Always);

saxParser->setExternalSchemaLocation("file:///C:/projekt/GPS/GDL/xerces/gdls
chema.xsd");
    saxParser->setValidationSchemaFullChecking(true);
    saxParser->setValidationConstraintFatal(true);
    saxParser->setExitOnFirstFatalError(true);
    saxParser->setErrorHandler(new GDLErrorHandler);

    try {

//saxParser->parse("file:///C:/projekt/GPS/GDL/xerces/example2.xml");
//Alternating between parsers. Always to no avail.
            parser->parse("file:///C:/projekt/GPS/GDL/xerces/example2.xml");
    } catch (SAXParseException &e) {...}


-----------------------------------
Using the DOMParser no errors are found no matter how faulty the XML source.
Using the SAXParser I get a SAXParseException alright, but this regardless
of how _correct_ the XML source is. The schema file is correct (tested in
XMLSpy and other tools).
Using the CLI sample app 'SAX2Count', things work fine (validates/fails as
it should), using 'DOMCount' I get an 'Unexpected exception' at line 2, char
12, no matter if the XML is valid or not....

Could there be encoding problems? Or do I just suck? ('fraid the latter is
more likely...)


Bests,

Christer Lindqvist

Stockholm


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


Re: Failing to validate using schema

Posted by Khaled Noaman <kn...@ca.ibm.com>.
A good starting point for you is to look at the sample programs (SAXCount, DOMPrint, ...)
that are shipped with the parser. Since schemas are namespace aware, you need to set the
namespace processing to true (parser->setDoNamespaces(true)), since it is false by default.

Regards,
Khaled

Christer Lindqvist wrote:

> Hi,
>
> I'm having trouble getting schema validation to work properly with 1.6.0;
> depending on whether I use a validating SAX- or DOMParser, I get different
> (erroneous) outcomes. It should be noted that I've just recently started
> using the Xerces C++, but have failed to find any help on the following.
> (My apologies if issues like this are dealt with in an FAQ I've overlooked.)
>
> Here's the thing ('parser' being the DOMParser ref., saxParser
> the....SAXParser!):
>
> -----------------------------------
>  try
>   {
>     parser->setDoSchema(true);
>     parser->setValidationScheme(DOMParser::Val_Auto);
>
> parser->setExternalSchemaLocation("file:///C:/projekt/GPS/GDL/xerces/gdlsche
> ma.xsd");
>     parser->setValidationSchemaFullChecking(true);              //These properties being
> set, you'd think it would work!
>     parser->setValidationConstraintFatal(true);
>     parser->setExitOnFirstFatalError(true);
>     parser->setIncludeIgnorableWhitespace(false);
>     parser->setErrorHandler(new GDLErrorHandler);    //The handler just
> throws the exception right back at caller..
>
>     parser->reset();
>
>     saxParser->setDoSchema(true);
>     saxParser->setValidationScheme(SAXParser::Val_Always);
>
> saxParser->setExternalSchemaLocation("file:///C:/projekt/GPS/GDL/xerces/gdls
> chema.xsd");
>     saxParser->setValidationSchemaFullChecking(true);
>     saxParser->setValidationConstraintFatal(true);
>     saxParser->setExitOnFirstFatalError(true);
>     saxParser->setErrorHandler(new GDLErrorHandler);
>
>     try {
>
> //saxParser->parse("file:///C:/projekt/GPS/GDL/xerces/example2.xml");
> //Alternating between parsers. Always to no avail.
>             parser->parse("file:///C:/projekt/GPS/GDL/xerces/example2.xml");
>     } catch (SAXParseException &e) {...}
>
> -----------------------------------
> Using the DOMParser no errors are found no matter how faulty the XML source.
> Using the SAXParser I get a SAXParseException alright, but this regardless
> of how _correct_ the XML source is. The schema file is correct (tested in
> XMLSpy and other tools).
> Using the CLI sample app 'SAX2Count', things work fine (validates/fails as
> it should), using 'DOMCount' I get an 'Unexpected exception' at line 2, char
> 12, no matter if the XML is valid or not....
>
> Could there be encoding problems? Or do I just suck? ('fraid the latter is
> more likely...)
>
> Bests,
>
> Christer Lindqvist
>
> Stockholm
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


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