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 Michael Glavassevich <mr...@ca.ibm.com> on 2008/09/08 07:21:08 UTC

Re: http://apache.org/xml/features/validation/dynamic does not work as documented

Hi Russell,

"Thamm, Russell" <ru...@dsto.defence.gov.au> wrote on 09/08/2008
12:08:59 AM:

> Hi,
> it appears that the dynamic validation feature does not work as
documented.
> If a document that does NOT specify a schema is parsed and the
> grammar pool contains a matching schema (ie a schema that defines
> the root element of the document),
> the document is validated.
> This IS NOT what the documentation says: "The parser will validate
> the document only if a grammar is specified."

It was specified by the grammar pool.

> When I googled this, I found someone who stated that:
> If dynamic validation is set to true, and validation is set to true,
> validation will only occur if a grammar is found.
> This appears to match the way the software works but contradicts the
> documentation (specified is not the same as found).
> Can I use grammar caching and get xerces to validate only documents
> that specify a schema?

Grammar pool is an interface [1]. You're in control of what it returns. If
you want it to only return a grammar if a schema location hint was provided
by the instance document then you need to change your implementation of
grammar pool to behave as such.

> Cheers
> Russell Thamm

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/grammars/XMLGrammarPool.html

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

RE: http://apache.org/xml/features/validation/dynamic does not work as documented

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

"Thamm, Russell" <ru...@dsto.defence.gov.au> wrote on 09/09/2008
12:27:58 AM:

> Hi Michael,
>
>
> I have changed the code so that retrieveInitialGrammarSet ALWAYS
> returns an empty array.
>
> I have modified retrieveGrammar to return null if the grammar is a
> schema and location hints are null.
>
> This does seem to resolve the problem.
>
> Presumably the code should behave in this manner only if dynamic
> validation is in force.
>
> Is this what you mean?

Not really. This might be the appropriate way to handle it in your
application but there's no requirement on the grammar pool that it behaves
that way.

> Cheers
> Russell Thamm

Thanks.

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

RE: http://apache.org/xml/features/validation/dynamic does not work as documented

Posted by "Thamm, Russell" <ru...@dsto.defence.gov.au>.
Hi Michael,
 
 
I have changed the code so that retrieveInitialGrammarSet ALWAYS returns
an empty array.
 
I have modified retrieveGrammar to return null if the grammar is a
schema and location hints are null.
 
This does seem to resolve the problem. 
 
Presumably the code should behave in this manner only if dynamic
validation is in force. 
 
Is this what you mean?
 
Cheers
Russell Thamm


________________________________

From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com] 
Sent: Tuesday, 9 September 2008 12:27 PM
To: j-users@xerces.apache.org
Subject: RE: http://apache.org/xml/features/validation/dynamic does not
work as documented



Hi Russell,

"Thamm, Russell" <ru...@dsto.defence.gov.au> wrote on 09/08/2008
10:23:58 PM:

> Hi Michael,
>  
> I don't understand. The Grammar Pool doesn't seem to have any say in
> the matter.
>  
> I have a schema, say a.xsd and two documents a.xml and b.xml.
>  
> The document a.xml references schema a.xsd and is valid according to
> the schema.
> The document b.xml has the same root element as a.xml but does NOT 
> reference the schema and is not valid according to the schema.
>  
> Assuming a.xsd is in the grammar cache, if I parse b.xml, the only 
> calls to the implementation of GrammarPool are to
retrieveInitialGrammarSet().

Probably because you return all the grammars from the pool from this
method. You don't have to. Your implementation can return a subset or
nothing (i.e. a zero length array) if it chooses.
  
> How does the Grammar Pool know whether or not a schema location hint
> was provided by the instance document?

You get this information when the retrieveGrammar() [1][2] method is
called. It will only be called if your grammar pool hasn't already
returned a grammar for the given target namespace. If your
implementation of retrieveInitialGrammarSet() already returns such a
grammar then retrieveGrammar() will never be called.

> The only info that I get passed is "http://www.w3.org/2001/XMLSchema"
and 
> http://www.w3.org/TR/REC-XML.
>  
> One thing that may be relevant is that my schema don't have a
targetnamespace.
>  
> Cheers
> Russell Thamm

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/gr
ammars/XMLGrammarPool.html#retrieveGrammar(org.apache.xerces.xni.grammar
s.XMLGrammarDescription)
[2]
http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/gr
ammars/XMLSchemaDescription.html

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


IMPORTANT: This email remains the property of the Australian Defence Organisation and is subject to the jurisdiction of section 70 of the CRIMES ACT 1914.  If you have received this email in error, you are requested to contact the sender and delete the email.



RE: http://apache.org/xml/features/validation/dynamic does not work as documented

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

"Thamm, Russell" <ru...@dsto.defence.gov.au> wrote on 09/08/2008
10:23:58 PM:

> Hi Michael,
>
> I don't understand. The Grammar Pool doesn't seem to have any say in
> the matter.
>
> I have a schema, say a.xsd and two documents a.xml and b.xml.
>
> The document a.xml references schema a.xsd and is valid according to
> the schema.
> The document b.xml has the same root element as a.xml but does NOT
> reference the schema and is not valid according to the schema.
>
> Assuming a.xsd is in the grammar cache, if I parse b.xml, the only
> calls to the implementation of GrammarPool are to
retrieveInitialGrammarSet().

Probably because you return all the grammars from the pool from this
method. You don't have to. Your implementation can return a subset or
nothing (i.e. a zero length array) if it chooses.

> How does the Grammar Pool know whether or not a schema location hint
> was provided by the instance document?

You get this information when the retrieveGrammar() [1][2] method is
called. It will only be called if your grammar pool hasn't already returned
a grammar for the given target namespace. If your implementation of
retrieveInitialGrammarSet() already returns such a grammar then
retrieveGrammar() will never be called.

> The only info that I get passed is "http://www.w3.org/2001/XMLSchema" and

> http://www.w3.org/TR/REC-XML.
>
> One thing that may be relevant is that my schema don't have a
targetnamespace.
>
> Cheers
> Russell Thamm

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/grammars/XMLGrammarPool.html#retrieveGrammar(org.apache.xerces.xni.grammars.XMLGrammarDescription)
[2]
http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/grammars/XMLSchemaDescription.html

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

RE: http://apache.org/xml/features/validation/dynamic does not work as documented

Posted by "Thamm, Russell" <ru...@dsto.defence.gov.au>.
Hi Michael,
 
I don't understand. The Grammar Pool doesn't seem to have any say in the
matter.
 
I have a schema, say a.xsd and two documents a.xml and b.xml.
 
The document a.xml references schema a.xsd and is valid according to the
schema.
The document b.xml has the same root element as a.xml but does NOT
reference the schema and is not valid according to the schema.
 
Assuming a.xsd is in the grammar cache, if I parse b.xml, the only calls
to the implementation of GrammarPool are to retrieveInitialGrammarSet().
 
How does the Grammar Pool know whether or not a schema location hint was
provided by the instance document?
 
The only info that I get passed is "http://www.w3.org/2001/XMLSchema"
and http://www.w3.org/TR/REC-XML.
 
One thing that may be relevant is that my schema don't have a target
namespace.
 
Cheers
Russell Thamm

________________________________

From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com] 
Sent: Monday, 8 September 2008 2:51 PM
To: j-users@xerces.apache.org
Subject: Re: http://apache.org/xml/features/validation/dynamic does not
work as documented



Hi Russell,

"Thamm, Russell" <ru...@dsto.defence.gov.au> wrote on 09/08/2008
12:08:59 AM:

> Hi, 
> it appears that the dynamic validation feature does not work as
documented. 
> If a document that does NOT specify a schema is parsed and the 
> grammar pool contains a matching schema (ie a schema that defines 
> the root element of the document),
> the document is validated. 
> This IS NOT what the documentation says: "The parser will validate 
> the document only if a grammar is specified."

It was specified by the grammar pool.

> When I googled this, I found someone who stated that: 
> If dynamic validation is set to true, and validation is set to true,
> validation will only occur if a grammar is found. 
> This appears to match the way the software works but contradicts the
> documentation (specified is not the same as found).
> Can I use grammar caching and get xerces to validate only documents 
> that specify a schema?

Grammar pool is an interface [1]. You're in control of what it returns.
If you want it to only return a grammar if a schema location hint was
provided by the instance document then you need to change your
implementation of grammar pool to behave as such.

> Cheers 
> Russell Thamm

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/gr
ammars/XMLGrammarPool.html

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


IMPORTANT: This email remains the property of the Australian Defence Organisation and is subject to the jurisdiction of section 70 of the CRIMES ACT 1914.  If you have received this email in error, you are requested to contact the sender and delete the email.