> -----Original Message-----
> From: Boris Kolpackov [mailto:[EMAIL PROTECTED] 
> Sent: Friday, September 14, 2007 1:24 PM
> To: [email protected]
> Subject: Re: More than one Schema Possible ?
> 
> Hi Dale,
> 
> EXT-Pennington, Dale K <[EMAIL PROTECTED]> writes:
> 
> > Now the method I envision would work as follows :
> > 1) Do a non-validating pass with no schema specified.
> > 2) Get the root element from the first pass, use it to 
> determine the 
> > actual message type and reparse/validate with the 
> appropriate schema 
> > specified.
> 
> I think there is a better way to handle this. From your 
> description I gather that you have different root element 
> names for different messages. In this case you can load and 
> cache the schemas for all possible message types. When the 
> parser tries to validate an XML instance it will look for the 
> corresponding root element grammar in the cache and use that 
> to validate.
> 
> The code for caching schemas looks along these lines:
> 
>     const XMLCh ls_id [] = {chLatin_L, chLatin_S, chNull};
> 
>     // Get an implementation of the Load-Store (LS) interface.
>     //
>     DOMImplementation* impl (
>       DOMImplementationRegistry::getDOMImplementation (ls_id));
> 
>     // Create a DOMBuilder.
>     //
>     xml::dom::auto_ptr<DOMBuilder> parser (
>       
> impl->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0));
> 
>     // Discard comment nodes in the document.
>     //
>     parser->setFeature (XMLUni::fgDOMComments, false);
> 
>     // Enable datatype normalization.
>     //
>     parser->setFeature (XMLUni::fgDOMDatatypeNormalization, true);
> 
>     // Do not create EntityReference nodes in the DOM tree.
>     //
>     parser->setFeature (XMLUni::fgDOMEntities, false);
> 
>     // Perform namespace processing.
>     //
>     parser->setFeature (XMLUni::fgDOMNamespaces, true);
> 
>     // Do not include ignorable whitespace in the DOM tree.
>     //
>     parser->setFeature 
> (XMLUni::fgDOMWhitespaceInElementContent, false);
> 
>     // Enable validation.
>     //
>     parser->setFeature (XMLUni::fgDOMValidation, true);
>     parser->setFeature (XMLUni::fgXercesSchema, true);
>     parser->setFeature (XMLUni::fgXercesSchemaFullChecking, false);
> 
>     // Initialize the schema cache.
>     //
>     parser->loadGrammar ("library.xsd",Grammar::SchemaGrammarType,
true);
>     parser->setFeature (XMLUni::fgXercesUseCachedGrammarInParse,
true);
> 
> It is taken from one of our examples and uses our 
> dom::auto_ptr to simplify memory management but the overall 
> idea is the same even if you don't use it.
> 
> Boris
> 

Since I currently have multiple Schema files, would I call loadGrammar
multiple times (1 per Schema file) or would I need to produce a new
Schema file that was the union of the other Schema file ?

Thanks

Dale

Reply via email to