I am trying to set up grammar caching and have things working nicely for
XML schemas but not for DTDs.  I am effectively doing the following:
    xercesc::XMLGrammarPool* grammarPool =
        xercesc::XMLGrammarPoolImpl(xercesc::XMLPlatformUtils::fgMemoryManager);

    parser = 
xercesc::XMLReaderFactory::createXMLReader(xercesc::XMLPlatformUtils::fgMemoryManager,
                                                        grammarPool));
    parser->setFeature(xercesc::XMLUni::fgXercesCacheGrammarFromParse, true);
    parser->setProperty(xercesc::XMLUni::fgXercesScannerName,
                        
static_cast<void*>(const_cast<XMLCh*>(xercesc::XMLUni::fgDGXMLScanner)));
    parser->setFeature(xercesc::XMLUni::fgSAX2CoreValidation, true);

When an XML document with no internal subset is parsed referring to an
external DTD:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE library SYSTEM "example.dtd">
    <library> ...
I get the error:
    (system id 'example-dtd.xml', line 2, char 40): An exception occurred!
    Type:NoSuchElementException, Message:The key '{0}' could not be found
    in the hash table

I put some printf()s into my resolveEntity() call back and was interested
to see resolveEntity() being called twice.  The first time with a null
publicId and 'example.dtd' as the systemId, the second time with an empty
string for the publicId and 'example.dtd' as the systemId.

This error does not occur if I replace the lines
    parser = 
xercesc::XMLReaderFactory::createXMLReader(xercesc::XMLPlatformUtils::fgMemoryManager,
                                                        grammarPool));
    parser->setFeature(xercesc::XMLUni::fgXercesCacheGrammarFromParse, true);
with
    parser = xercesc::XMLReaderFactory::createXMLReader();
and therefore do not use grammar caching.  When no caching is used, I just
get one call to resolveEntity().

As mentioned above, caching is working fine for XML schemas when I use the
SGXMLScanner.

At one point, I suspected that maybe I needed to call setSystemId() and/or
setPublicId() on the InputSource I return from resolveEntity(), and did:
    buf->setSystemId(p_systemId);
    buf->setPublicId(NIL);
But this didn't help.

Is this a known problem?  Any suggestions beyond submitting a testcase to
jira?

Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to