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 "Rafael Sousa (Ext_Altior)" <Ra...@siemens.com> on 2005/12/06 17:54:29 UTC

RE: Grammar building and caching during initialization

Hi David! 

Thanks. That looks like the best way to me.

The SCMPrint sample gives an example of its use. But I'm not getting the results I expected. The first time parse() is called still takes much more time than all the next.

Is it correct/enough to do this:

parser->loadGrammar("/home/rsousa/Schema.xsd", Grammar::SchemaGrammarType, true);

after instanciating the parser (I'm using SAXParser), or do I need to do anything else?

Best regards,

Rafael Sousa


-----Original Message-----
From: David Bertoni [mailto:dbertoni@apache.org] 
Sent: terça-feira, 29 de Novembro de 2005 2:42
To: c-users@xerces.apache.org
Subject: Re: Grammar building and caching during initialization

Rafael Sousa (Ext_Altior) wrote:
> Hi everybody!
>  
> The possibility to cache the grammar from the schemas that are used for
> validation is very useful. That way, we can avoid reading many times the
> same schema file from disk, and building the same grammar objects over
> and over.
>  
> But what is the best way to explicitly do this, without having to wait
> for the first XML message that uses some schema? Because what happens is
> that the first time a schema is used takes much more time than the next
> ones. It would be nice to be able to construct and cache the grammar
> we'll use during system initialization, where time requisites are more
> lenient...
>  

You probably want to use the loadGrammar() API on the parser instance 
you're using.  Be sure to call it with the last parameter as true, so it 
keeps the grammar in its cache.

Dave