You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Or Erlichson <Or...@sapiens.com> on 2016/05/05 07:14:43 UTC

Cant load schema in version 2.6.0

I am trying to load the example schema provided by xerces (personal.xsd) using an absolute path,
However it always fails to load it

void ValidateSchema(const char* schemaFilePath, const char* xmlFilePath)
{
       XercesDOMParser domParser;
       if (domParser.loadGrammar(schemaFilePath, Grammar::SchemaGrammarType) == NULL)
       {
              fprintf(stderr, "couldn't load schema\n");
              return;
       }

       ParserErrorHandler parserErrorHandler;

       domParser.setErrorHandler(&parserErrorHandler);
       domParser.setValidationScheme(XercesDOMParser::Val_Auto);
       domParser.setDoNamespaces(true);
       domParser.setDoSchema(true);
       domParser.setValidationConstraintFatal(true);

       domParser.parse(xmlFilePath);
       if (domParser.getErrorCount() == 0)
              printf("XML file validated against the schema successfully\n");
       else
              printf("XML file doesn't conform to the schema\n");
}

domParser.loadGrammar(schemaFilePath, Grammar::SchemaGrammarType) returns null when the absolute path of personal.xsd is given to it
The XML I'm using to test is also the one provided in the samples, personal.xml, though since the schema isn't loaded it returns errors if allowed to continue pass the loadGrammar function.

What am I doing wrong?


Thank you.


Re: Cant load schema in version 2.6.0

Posted by Vitaly Prapirny <ma...@mebius.net>.
Hi,

You can set error handler before the loadGrammar call and see what's 
going on.

Good luck!
   Vitaly

Or Erlichson wrote:
> I am trying to load the example schema provided by xerces (personal.xsd) using an absolute path,
> However it always fails to load it
>
> void ValidateSchema(const char* schemaFilePath, const char* xmlFilePath)
> {
>         XercesDOMParser domParser;
>         if (domParser.loadGrammar(schemaFilePath, Grammar::SchemaGrammarType) == NULL)
>         {
>                fprintf(stderr, "couldn't load schema\n");
>                return;
>         }
>
>         ParserErrorHandler parserErrorHandler;
>
>         domParser.setErrorHandler(&parserErrorHandler);
>         domParser.setValidationScheme(XercesDOMParser::Val_Auto);
>         domParser.setDoNamespaces(true);
>         domParser.setDoSchema(true);
>         domParser.setValidationConstraintFatal(true);
>
>         domParser.parse(xmlFilePath);
>         if (domParser.getErrorCount() == 0)
>                printf("XML file validated against the schema successfully\n");
>         else
>                printf("XML file doesn't conform to the schema\n");
> }
>
> domParser.loadGrammar(schemaFilePath, Grammar::SchemaGrammarType) returns null when the absolute path of personal.xsd is given to it
> The XML I'm using to test is also the one provided in the samples, personal.xml, though since the schema isn't loaded it returns errors if allowed to continue pass the loadGrammar function.
>
> What am I doing wrong?
>
>
> Thank you.
>
>