[xsd-users] Schema caching example: enabe schema caching automatically

Ashish Singhal ashish at ashishsinghal.com
Thu Sep 26 06:30:53 EDT 2013


>You can always wrap the generated parsing functions (I assume that's
>what you mean by "generated constructors") and hide all the schema
>caching

My concern is with having to change every invocation to use the wrapper -
my application has hundreds of invocations using the non-cached parser.
Tracking them all down will be difficult. Is there an approach that can
help avoid this?


On Thu, Sep 26, 2013 at 11:09 AM, Boris Kolpackov
<boris at codesynthesis.com>wrote:

> Hi Ashish,
>
> Ashish Singhal <ashish at ashishsinghal.com> writes:
>
> > Are there any hooks for configuring the xerces-c parser used for loading
> > xml to cache the schema automatically?
> >
> > I had a look at the schema caching example supplied with xsd and it
> works,
> > but it ends up being a 2 stage process:
> >
> > 1) load the xml schema using xerces-c (with the caching parser)
> > 2) construct the xsd generated object.
> >
> > I'd like to skip #1 and have it done automatically by xsd generated code.
>
> Normally, the idea behind schema caching is that you want to do it once
> and then reuse the grammar to parse multiple documents. And to achieve
> this, you need to reuse the XML parser. On the other hand, the generated
> parsing functions create a new XML parser for every invocation, so even
> if there were a way to configure the parser used, it would be destroyed
> at the end of the call. That's why to do caching you need to have your
> own XML-to-DOM stage. This way you can make sure the same parser is used,
> in some application-specific way.
>
>
> > The 2 stage process is inconvenient, as I have a significant amount of
> code
> > that loads xml files using the generated constructors. It would be
> > difficult to change everything to the two stage loading process.
>
> You can always wrap the generated parsing functions (I assume that's
> what you mean by "generated constructors") and hide all the schema
> caching. You will need to make sure that they all use a single
> parser in some way (e.g., a global parser for a single-threaded
> application and maybe TLS for multi-threaded). You could probably
> even make this wrapper a function template.
>
> Note also that it is possible to tell Xerces-C++ to load and cache
> the schemas automatically, as it parses XML documents that reference
> them instead of pre-loading them manually at the beginning.
>
> Boris
>


More information about the xsd-users mailing list