Hi Milan,
if I recall it correctly, that mail was addressing a different problem (forcing validation against a DTD); and this required some carefully coding.
If you need to validate against one or more XMLSchemas, this should work:


XercesDOMParser * parser = new XercesDOMParser;

MemBufInputSource is("<xs:schema....", dwTextLength, "");
parser->loadGrammar(is, Grammar::SchemaGrammarType, true);

parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->useCachedGrammarInParse(true);
parser->parse(...);

delete parser;

in short, you invoke loadGrammar for every schema you want to load, specifying the third argument (toCache) to true; this way all the schemas will be kept inside the GrammarResolver of the parser. By calling setValidationScheme(XercesDOMParser::Val_Always) you tell the parser to always validate the data being parsed (even if it doesn't have a reference to a schema), and by calling useCachedGrammarInParse() you tell him to use this cache of schemas.

Hope this helps,
Alberto

At 11.08 31/12/2004 +0100, Milan Tomic wrote:
Hi Alberto,

        I've succeeded to manage setExternalSchemaLocation() to work OK,
but I would much raither like to use loadGrammar(). I've found in mail
archives (
http://www.mail-archive.com/xerces-c-dev@xml.apache.org/msg13604.html )
your response on this topic and I did the same using this code:

MemBufInputSource * is = new MemBufInputSource((const unsigned char
*const)hRes, dwFileLength, "Some text...");

XercesDOMParser * schema = new XercesDOMParser;
Grammar * pSchema = schema->loadGrammar(*is,
Grammar::SchemaGrammarType);
schemaValidator = new SchemaValidator();
schemaValidator->setGrammar(pSchema);

XercesDOMParser * parser = new XercesDOMParser(schemaValidator);
parser->setDoNamespaces(true);
parser->setCreateEntityReferenceNodes(true);

DOMTreeErrorReporter * errorHandler = new DOMTreeErrorReporter();
parser->setErrorHandler(errorHandler);

parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
parser->setValidationScheme(XercesDOMParser::Val_Always);

parser->parse("C:\\my.xml");

        And when using files I have attached with my previous post, I
got this error:

Fatal Error at file
C:\my.xml
, line
1
column
116
Message:
An exception occurred! Type:RuntimeException, Message:A DOCTYPE was seen
but the installed validator does not understand DTDs

        What is it? Btw, does input stream ( for loadGrammar() ) have to
end with 0 byte? If not, Is it error if it does?

Thank you,
Milan



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to