You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "Gierschner, Frank" <Fr...@realtech.com> on 2008/08/26 09:08:40 UTC
Extent and usage of grammar caching
Hello.
Does the so-called "grammar-caching" take place within the currently
used parser (e.g. DOMBuilder) only [meaning: grammar cache is deleted
when the parser is released] or is the grammar held somewhere in memory
until XMLPlatformUtils::Terminate(); or any other method (like
resetDocumentPool() etc.) is called?
Until now I believe it is attached to the parser but I cannot find an
explicit confirmation for that in the documentation.
If so and grammar-caching throughout the lifetime of my program would be
required is the only way to do so like described here
(http://www-128.ibm.com/developerworks/webservices/library/x-xsdxerc.htm
l) or in using synchronized access to one single parser instance?
Are there additional possibilities without using (de-)serialization,
e.g. can I share a an instance of XMLGrammarPool with multiple parser
instances?
Regards
Frank
Re: Extent and usage of grammar caching
Posted by David Bertoni <db...@apache.org>.
John Snelson wrote:
> Hi Frank,
>
> The cached grammars are owned by the XMLGrammarPool. If you don't
> provide your own XMLGrammarPool to a parser, then it will use it's own,
> which will be deleted when the parser is deleted.
>
> You can share an XMLGrammarPool amongst threads by locking it using
> XMLGrammarPool::lockPool(). Using this method, you should first populate
> the grammar pool with the grammars you want. Then you can lock it and
> construct as many parsers with it as you need.
>
> The one problem I haven't solved using this method is that Xerces-C
> refuses to parse an XML document with an internal DTD subset if the
> grammar pool is locked. This means it is not compliant with the XML
> specification :-(.
The easiest solution for this problem is to chain grammar pools
together. You can do it by implementing a GrammarPool that contains a
pointer to another, read-only GrammarPool that contains the Grammar
instances you want to cache. When the parser requests a Grammar, look
in the writable pool first. If it's not there, check the read-only
pool. When the parser wants to add a new Grammar to the pool, add it to
the writable pool. This also covers the case where the XML document has
an extra schema location hint.
You can also implement a schema like this using the GrammarResolver
interface, but using chained GrammarPool instances is simpler.
I devised a scheme like this when I worked at IBM on the XML database
implementation in DB2.
Dave
Re: Extent and usage of grammar caching
Posted by John Snelson <jo...@oracle.com>.
Hi Frank,
The cached grammars are owned by the XMLGrammarPool. If you don't
provide your own XMLGrammarPool to a parser, then it will use it's own,
which will be deleted when the parser is deleted.
You can share an XMLGrammarPool amongst threads by locking it using
XMLGrammarPool::lockPool(). Using this method, you should first populate
the grammar pool with the grammars you want. Then you can lock it and
construct as many parsers with it as you need.
The one problem I haven't solved using this method is that Xerces-C
refuses to parse an XML document with an internal DTD subset if the
grammar pool is locked. This means it is not compliant with the XML
specification :-(.
John
Gierschner, Frank wrote:
> Hello.
>
> Does the so-called "grammar-caching" take place within the currently
> used parser (e.g. DOMBuilder) only [meaning: grammar cache is deleted
> when the parser is released] or is the grammar held somewhere in memory
> until XMLPlatformUtils::Terminate(); or any other method (like
> resetDocumentPool() etc.) is called?
> Until now I believe it is attached to the parser but I cannot find an
> explicit confirmation for that in the documentation.
>
> If so and grammar-caching throughout the lifetime of my program would be
> required is the only way to do so like described here
> (http://www-128.ibm.com/developerworks/webservices/library/x-xsdxerc.htm
> l) or in using synchronized access to one single parser instance?
>
> Are there additional possibilities without using (de-)serialization,
> e.g. can I share a an instance of XMLGrammarPool with multiple parser
> instances?
>
> Regards
> Frank
>
--
John Snelson, Oracle Corporation http://snelson.org.uk/john
Berkeley DB XML: http://oracle.com/database/berkeley-db/xml
XQilla: http://xqilla.sourceforge.net