You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Patrik Stellmann <pa...@volleynet.de> on 2017/01/22 07:04:11 UTC

Grammar caching with multiple schemas for the same target namespace

Hi,

I'm recursively processing DITA maps using the SAXParser with 
XMLGrammarPool. All files are in the default namespace but have 
different XML schemas associated (set my @xsi:noNamespaceSchemaLocation).

The problem is that the XMLGrammarPool as well as the SAXParser assumes 
that the schema only depends on the targetNamespace. Thus, they will use 
the same schema for a topic file as it used for a map file.

I already implemented my own XMLGrammarPool class that checks if two 
schema descriptions are equal based on their system id. But it seems 
that the parser stores a mapping between namespace and systemId. Thus, 
it asks the grammar pool for a schema with the map system id when 
processing a topic.

My current workaround is to create a new instance of the SAXParser for 
each file I'm processing. This works fine, but I'm wondering if I could 
improve the performance by reusing the same instance for all files. But 
I couldn't find out how to change the behavior for getting the grammar!?

Thanks for any hints.

Regards,
Patrik

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Grammar caching with multiple schemas for the same target namespace

Posted by Patrik Stellmann <pa...@volleynet.de>.
Thanks for the hint. My own implementation was already very close to 
that of SoftReferenceGrammarPool. However, even when using the exact 
implementation of SoftReferenceGrammarPool I still get an error for 
unknown root element when parsing the second document with a different 
schema. So the problem and solution seem to lay outside of the grammar 
pool but somewhere in the xml reader. Do you have maybe another idea 
where to look?

Thanks and regards,
Patrik

Am 23.01.2017 um 17:09 schrieb Michael Glavassevich:
> Hi,
>
> I thought we (at least partially) addressed this issue in the JAXP 1.3 
> implementation. I'd suggest having a look at how the 
> SoftReferenceGrammarPool [1] works, as its purpose is to cache 
> grammars based on both their schema location and target namespace.
>
> Thanks.
>
> [1] 
> http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/SoftReferenceGrammarPool.java
>
> Michael Glavassevich
> XML Technologies and WAS Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Patrik Stellmann <pa...@volleynet.de> wrote on 01/22/2017 02:04:11 AM:
>
> > Hi,
> >
> > I'm recursively processing DITA maps using the SAXParser with
> > XMLGrammarPool. All files are in the default namespace but have
> > different XML schemas associated (set my 
> @xsi:noNamespaceSchemaLocation).
> >
> > The problem is that the XMLGrammarPool as well as the SAXParser assumes
> > that the schema only depends on the targetNamespace. Thus, they will 
> use
> > the same schema for a topic file as it used for a map file.
> >
> > I already implemented my own XMLGrammarPool class that checks if two
> > schema descriptions are equal based on their system id. But it seems
> > that the parser stores a mapping between namespace and systemId. Thus,
> > it asks the grammar pool for a schema with the map system id when
> > processing a topic.
> >
> > My current workaround is to create a new instance of the SAXParser for
> > each file I'm processing. This works fine, but I'm wondering if I could
> > improve the performance by reusing the same instance for all files. But
> > I couldn't find out how to change the behavior for getting the grammar!?
> >
> > Thanks for any hints.
> >
> > Regards,
> > Patrik
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-users-help@xerces.apache.org
>


Re: Grammar caching with multiple schemas for the same target namespace

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi,

I thought we (at least partially) addressed this issue in the JAXP 1.3 
implementation. I'd suggest having a look at how the 
SoftReferenceGrammarPool [1] works, as its purpose is to cache grammars 
based on both their schema location and target namespace.

Thanks.

[1] 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/SoftReferenceGrammarPool.java

Michael Glavassevich
XML Technologies and WAS Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Patrik Stellmann <pa...@volleynet.de> wrote on 01/22/2017 02:04:11 AM:

> Hi,
> 
> I'm recursively processing DITA maps using the SAXParser with 
> XMLGrammarPool. All files are in the default namespace but have 
> different XML schemas associated (set my 
@xsi:noNamespaceSchemaLocation).
> 
> The problem is that the XMLGrammarPool as well as the SAXParser assumes 
> that the schema only depends on the targetNamespace. Thus, they will use 

> the same schema for a topic file as it used for a map file.
> 
> I already implemented my own XMLGrammarPool class that checks if two 
> schema descriptions are equal based on their system id. But it seems 
> that the parser stores a mapping between namespace and systemId. Thus, 
> it asks the grammar pool for a schema with the map system id when 
> processing a topic.
> 
> My current workaround is to create a new instance of the SAXParser for 
> each file I'm processing. This works fine, but I'm wondering if I could 
> improve the performance by reusing the same instance for all files. But 
> I couldn't find out how to change the behavior for getting the grammar!?
> 
> Thanks for any hints.
> 
> Regards,
> Patrik
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org