On Wed, Sep 19, 2012 at 9:31 PM, Erik Sjölund <[email protected]> wrote: > Is it possible serialize out one binary file per schema file and then > later just load in a subset of the binary files into an > XMLGrammarPool?
I did some experimenting: I modified the "embedded" example from CodeSynthesis XSD and added a second schema file containing a polymorphic element (belonging to a substitutionGroup). The two schema files were "compiled" separately into two binary files with the xsdbin executable ( http://scm.codesynthesis.com/?p=xsd/xsd.git;a=blob_plain;f=examples/cxx/tree/embedded/xsdbin.cxx;hb=HEAD ). In my modified "driver.cxx" I had grammar_input_stream is (library_schema, sizeof (library_schema)); gp->deserializeGrammars(&is); grammar_input_stream is2 (polymorphic_schema, sizeof (polymorphic_schema)); gp->deserializeGrammars(&is2); When calling deserializeGrammars the second time I got this error "unable to load schema: string pool is not empty" So it is not working. I also found that in the Xerces source code it is stated that multiple deserializations are not supported: erik@linux:~/tmp$ grep -A2 "Multiple deserializations" xerces-c-3.1.1/src/xercesc/framework/XMLGrammarPoolImpl.hpp * Multiple deserializations * * Not supported erik@linux:~/tmp$ The second idea I had was to use two XMLGrammarPool and let each one of them run deserializeGrammars once. After that I would move a Grammar from one XMLGrammarPool to the other with the help of the functions Grammar* XMLGrammarPool::orphanGrammar(const XMLCh *const nameSpaceKey) bool XMLGrammarPool::cacheGrammar(Grammar *const gramToCache) ( see http://xerces.apache.org/xerces-c/apiDocs-3/classXMLGrammarPool.html ) There seems to be a bug related to this https://issues.apache.org/jira/browse/XERCESC-1798 A workaround for the bug is found in the test case file (test.cpp): erik@linux:/tmp$ wget -q https://issues.apache.org/jira/secure/attachment/12381097/test.cpp erik@linux:/tmp$ grep -A7 -B1 "Copy string" test.cpp /* // Copy string pool contents. // const XMLStringPool* src = grpool->getURIStringPool (); XMLStringPool* dst = newgrpool->getURIStringPool (); for (unsigned int i = 1; i < src->getStringCount () + 1; ++i) dst->addOrFind (src->getValueForId (i)); */ I tried to move the Grammar in this way but it didn't work. When I later parsed an XML file I got this error: "error: no declaration found for element 'polymorphic:polymorphic'" which is the same error I would have got if I wouldn't have used the second schema at all. But I don't understand how the workaround should work. If the target XMLGrammarPool has a non-empty XMLStringPool, the strings will get new Id numbers, wouldn't they? The Grammar that was moved would then contain wrong string Id numbers. But I don't know the details, so I might be missing something here. cheers, Erik Sjölund
