I have looked at the testcase you submitted, and I found two things:
1) the exception you get when using cached grammars and the DGXMLScanner is caused by GrammarResolver::orphanGrammar; to fix it, apply this diff
diff -u -r1.29 GrammarResolver.cpp --- GrammarResolver.cpp 29 Sep 2004 19:27:07 -0000 1.29 +++ GrammarResolver.cpp 3 Dec 2004 16:16:23 -0000 @@ -439,7 +439,8 @@ Grammar* grammar = fGrammarPool->orphanGrammar(nameSpaceKey); if (grammar) { - fGrammarFromPool->removeKey(nameSpaceKey); + if (fGrammarFromPool->containsKey(nameSpaceKey)) + fGrammarFromPool->removeKey(nameSpaceKey); return grammar; } // It failed to remove it from the grammar pool either because it
2) as for the extra resolveEntity() you see, it's by design; GrammarResolver now stores the DTDs using their systemID as key (instead of the root element name), so, when caching is on, an extra call to resolveEntity is done in order to be able to invoke InputSource::getSystemId(). At that point, if the systemId is already in the cache, the input source is not parsed; if it is not in the cache, a new reader is created (and this triggers a new resolveEntity call)
I will change this to at least avoid the second call (as we have already resolved the DTD).
Thanks for the testcase, Alberto
At 16.42 03/12/2004 +1100, Daniel McLean wrote:
I've put together a demo based on one of the sample programs shipped with Xerces. The demo creates a Xerces GrammarPoolImpl then conducts a number of validating XML parses using that grammar pool when caching is enabled for the parser. The test documents include an XML file referring to a DTD and an XML file referring to an XML schema. Each type of parse is done twice in succession to observe the caching behaviour of Xerces, with a new parser instance created for each parse. The parses done include:
DGXMLScanner without caching involving DTD validation DGXMLScanner with caching involving DTD validation
IGXMLScanner without caching involving DTD validation IGXMLScanner with caching involving DTD validation
SGXMLScanner without caching involving XML schema validation SGXMLScanner with caching involving XML schema validation
I ran with on an Fedora Core 1 linux x86 platform using Xerces 2.6.0.
I see a number of surprising things (refer to output below): - parsing fails when caching is enabled whilst using the DGXMLScanner - when using DGXMLScanner or IGXMLScanner for DTD validation, the DTD appears to be re-resolved for each parse. I haven't checked whether the DTD is actually being re-parsed after being resolved each time, but I wonder why it is being resolved each time if it is supposedly being cached - the DTD is being resolved twice on the first parse when parsing with a DTD and caching enabled. This seems questionable.
I've attached a tarball containing the files for the demo, which should work after being unpacked into the samples directory.
Regards,
Daniel
doParse dtdDGXML parse #1 resolveEntity("", "example.dtd") parse #2 resolveEntity("", "example.dtd") ---------------------------- doParse dtdDGXMLCaching parse #1 resolveEntity(null, "example.dtd") resolveEntity("", "example.dtd")
Fatal Error at (file /home/daniel/xerces/xerces-c-src_2_6_0/samples/GrammarCache/example-dtd.xml, line 2, char 40): An exception occurred! Type:NoSuchElementException, Message:The key '{0}' could not be found in the hash table parse #2 resolveEntity(null, "example.dtd") resolveEntity("", "example.dtd")
Fatal Error at (file /home/daniel/xerces/xerces-c-src_2_6_0/samples/GrammarCache/example-dtd.xml, line 2, char 40): An exception occurred! Type:NoSuchElementException, Message:The key '{0}' could not be found in the hash table ---------------------------- doParse dtdIGXML parse #1 resolveEntity("", "example.dtd") parse #2 resolveEntity("", "example.dtd") ---------------------------- doParse dtdIGXMLCaching parse #1 resolveEntity("", "example.dtd") resolveEntity("", "example.dtd") parse #2 resolveEntity("", "example.dtd") ---------------------------- doParse xsd parse #1 resolveEntity("", "example.xsd") parse #2 resolveEntity("", "example.xsd") ---------------------------- doParse xsdCaching parse #1 resolveEntity("", "example.xsd") parse #2 ----------------------------
--------------------------------------------------------------------- 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]