Dave Given your explaination on how to use methods loadGrammar and useCachedCrammarInParse, I tried the following below and it appears that the parser attempted to use the DTD specified in the XML file rather than the one I loaded and cached using the loadGrammar method. I thought this would force the parser to use the dtd specified in the loadGrammar method call. What am I missing here? Using Xerces 2.7.0 DOM Impl.
Code snippet ================================ _XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Always); _XmlDOMParser->setDoSchema(false); //load grammar and cache it _XmlDOMParser->setLoadExternalDTD(true); _XmlDOMParser->loadGrammar(dtd, Grammar::DTDGrammarType, true); _XmlDOMParser->setSkipDTDValidation(false); _XmlDOMParser->useCachedGrammarInParse(true); _XmlDOMParser->parse(xmlDoc2Parse); ..... The attempt to parse and validate got the error below: The following error occurred during the XML validation XML Parser Fatal Error in file "/net/sinai/home/d/dcd9420/labs/bcmeXmlLab/boldMetaData-PP-777-D633W101- EAD-51-20070905.xml" <?xml version="1.0" encoding="UTF-8"?> Line 2::Column 92 <!DOCTYPE DOCUMENT SYSTEM "http//web/dtd/ddps_mmm_meta_3.dtd"> Parser Error Message: An exception occurred! Type:NetAccessorException, Message:Could not read from the socket for URL 'http//web/dtd/ddps_mmm_meta_3.dtd' =================================== Snippet of XML file <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE DOCUMENT SYSTEM http//web/dtd/ddps_mmm_meta_3.dtd"> <DOCUMENT> <APPLICATION VERSION="2.0.3.0507">TECHNICAL DOCUMENTS</APPLICATION> <PRODUCT_NUMBER>D633W101-EAD</PRODUCT_NUMBER> ==================================== 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