Dantzler, DeWayne C wrote:
Ok, can someone explain to me what the method 'loadGrammar' actually
does and when and why I would use it? Likewise, the same questions for
the method 'useCachedGrammarInParse'. Hopefully, this will help me to
understand how the Parsers validates against a DTD. What is the meaning
of 'grammar' in this context and how does the parser generate and use
it?
It means "load a grammar from an external resource and return a pointer to the resulting object." You can use this object for parsing and validating instance documents.

You would mostly want to do this if you want to share a grammar between parsers, or you are interesting in just the grammar object itself. For example, it's possible to load a schema grammar, then query the grammar for interesting information about the types the schema defines.

The flag 'usedCachedGrammarInParse' tells to parser to use any cached grammar instead of loading the grammar specified by the instance document. Consider an instance document with schema location hints. Those hints might point to a different schema than the one in the parser's cache. If the parser were to always use the cached grammar, there might be cases where that would not be the right one. On the other hand, there might be cases where you would want to force the parser to use a specific grammar.

"Grammar" in this context means either a DTD or schema, which can be thought of as grammars for validating particular kinds of XML documents.


BTW... I read the header files docs on these methods, but could not make
sense of what is meant by 'Preparse' schema/dtd grammar. See below.
Thanks
"Preparse" simply means the parser reads the grammar and build the appropriate objects it uses for validating XML instance documents.

The 'toCache' flag instructs the parser to put the grammar object in its internal cache.

The 'useCachedGrammarInParse' property instructs the parser to always prefer cached grammars over those specified by the instance document.

Dave

Reply via email to