I have an XML file that does not have a DTD reference in the file. (i.e
<!DOCTYPE records SYSTEM "some.xml file path">, but I want to validate
the XML against an external DTD using the Xerces library. I've tried the
setting below, but the parser does not recognize or load the specified
DTD. The parser reports errors for 'ALL' element tags as undefined!! The
Entity Resolver handler is never called by the parser!! How do I get the
parser to 'load' and 'use' an external DTD given no DTD reference is
specified in the XML file?
*Override the default Entity Resolver and use mine
_XmlDOMParser->setEntityResolver(resolver);
_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Always);
_XmlDOMParser->setDoSchema(false);
* This method allows users to enable or disable the loading of
external DTD.
* When set to false, the parser will ignore any external DTD
completely
* if the validationScheme is set to Val_Never.
_XmlDOMParser->setLoadExternalDTD(true);
* Preparse schema grammar (XML Schema, DTD, etc.) via a file path
or URL
*
* This method invokes the preparsing process on a schema grammar
XML
* file specified by the file path parameter. If the 'toCache' flag
* is enabled, the parser will cache the grammars for re-use. If a
grammar
* key is found in the pool, no caching of any grammar will take
place.
_XmlDOMParser->loadGrammar(dtd, Grammar::DTDGrammarType,
false);
_XmlDOMParser->setSkipDTDValidation(false);
* This method allows users to enable or disable the use of cached
* grammars. When set to true, the parser will use the cached
grammar,
* instead of building the grammar from scratch, to validate XML
* documents.
_XmlDOMParser->useCachedGrammarInParse(true);
_XmlDOMParser->parse(xmlDoc2Parse);