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 po...@skynet.ie on 2007/06/21 16:38:42 UTC

Grammar returned from XMLGrammarPreparser.preparseGrammar()

Hi there,

I'm working on some code that adds a set of schemas to an XMLGrammarPool
and then lock the pool. When an XML document is received it will attempt
to validate the XML using the corresponding schema from the pool. I'm
having some trouble implementing this which has lead me to the following -

I've noticed something strange with the XMLGrammarPreparser. Basically I
call preparseGrammar() for schema1.xsd and print out the grammar
description of the grammar that is returned. Then I call preparseGrammar()
for schema2.xsd and print out the grammar description of the grammar that
is returned. It appears that the same object is returned from both. Maybe
I'm missing something here but I would have expected these descriptions
would not be the same.

I've been able to reproduce this using the XMLGrammarBuilder example. Just
add a System.out after the call to preparseGrammar() on line 253. Here is
the output I get when running this -

>java -classpath .;../../resourcestore/jars/xercesimpl.jar
xni.XMLGrammarBuilder -a c:\workspace\schema1.xsd
c:\workspace\schema2.xsd

:c:\workspace\schema1.xsd:::
:c:\workspace\schema1.xsd:::
>

Can someone explain to me why this happens? I've spent most of the day
looking at it but I can't explain what is happening.

Thanks,
Dave.



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


Re: Grammar returned from XMLGrammarPreparser.preparseGrammar()

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

I'm guessing both schema1.xsd and schema2.xsd have the same target 
namespace. The default XMLGrammarPool implementation (XMLGrammarPoolImpl) 
caches one XSGrammar per namespace so will always return the XSGrammar 
built for the first schema. An XMLGrammarPool doesn't have to work like 
that. You could do something clever like merging XSGrammars or caching 
based on the target namespace and schema location. For examples of those 
see org.apache.xerces.impl.xs.XSLoaderImpl.XSGrammarMerger [1] and 
org.apache.xerces.jaxp.validation.SoftReferenceGrammarPool [2].

Thanks.

[1] 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSLoaderImpl.java?revision=406145&view=markup
[2] 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/SoftReferenceGrammarPool.java?revision=447235&view=markup

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

podgeen@skynet.ie wrote on 06/21/2007 10:38:42 AM:

> Hi there,
> 
> I'm working on some code that adds a set of schemas to an XMLGrammarPool
> and then lock the pool. When an XML document is received it will attempt
> to validate the XML using the corresponding schema from the pool. I'm
> having some trouble implementing this which has lead me to the following 
-
> 
> I've noticed something strange with the XMLGrammarPreparser. Basically I
> call preparseGrammar() for schema1.xsd and print out the grammar
> description of the grammar that is returned. Then I call 
preparseGrammar()
> for schema2.xsd and print out the grammar description of the grammar 
that
> is returned. It appears that the same object is returned from both. 
Maybe
> I'm missing something here but I would have expected these descriptions
> would not be the same.
> 
> I've been able to reproduce this using the XMLGrammarBuilder example. 
Just
> add a System.out after the call to preparseGrammar() on line 253. Here 
is
> the output I get when running this -
> 
> >java -classpath .;../../resourcestore/jars/xercesimpl.jar
> xni.XMLGrammarBuilder -a c:\workspace\schema1.xsd
> c:\workspace\schema2.xsd
> 
> :c:\workspace\schema1.xsd:::
> :c:\workspace\schema1.xsd:::
> >
> 
> Can someone explain to me why this happens? I've spent most of the day
> looking at it but I can't explain what is happening.
> 
> Thanks,
> Dave.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org


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