At 16.03 17/11/2005 +0000, Ciaran McHale wrote:
Hi Alberto,

Thanks for the prompt and detailed response.

Whenever a system is implemented in terms of itself, you always reach a
point where there are low-level primitives that cannot be expressed
"normally". I am not surprised to see this applies to the "schema for
schemas", but thanks for clarifying the issue for me.

What I want to do is write some code that will:

        /1/ Parse a ".xml" or ".xsd" file and do as much checking
            as Xerces will allow for that type of file, and then...

        /2/ Build a DOM tree for the parsed file.

I had a look at the API documentation for loadGrammar(). If I understand
your email and the documentation correctly then my algorithm should be
something like the following pseudo-code:

parser = new XercesDOMParser();
parser->setDoNamespaces(true);
parser->setErrorHandler(...);
if (inputFilename ends in ".xsd") {
    parser->setDoSchema(false);
    parser->setValidationScheme(XercesDOMParser::Val_Never);
    parser->loadGrammar(inputFilename, Grammar::SchemaGrammarType);
} else {
    parser->setDoSchema(true);
    parser->setValidationSchemaFullChecking(true);
    parser->setValidationScheme(XercesDOMParser::Val_Always);
}
parser->parse(inputFilename);

Yes, this will give you a validated DOM for either XML or XSD, throwing errors if the XSD is not valid, or if the XML is not valid according to the XSD it specifies. This leaves out only the case of XML files that don't point to either a DTD or XSD, that will always generate errors (but maybe this is what you want).

In effect, I should use full schema checks for ".xml" files, but for
".xsd" files I should turn off schema checking and compensate for this
by calling loadGrammar(). Is this correct?

I think loadGrammar overrides whatever setting you specified, as it knows what kind of checks must be done on an XSD; so probably calling
        parser->setDoSchema(false);
        parser->setValidationScheme(XercesDOMParser::Val_Never);
is an overkill, but it shouldn't hurt you.

Alberto




Regards,
Ciaran.
--
Ciaran McHale, Ph.D.        Email: [EMAIL PROTECTED]
Principal Consultant        Tel: +44-7866-416-134 (mobile)
IONA Technologies, UK       WWW: www.iona.com


Reply via email to