xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Glavassevich <mrgla...@ca.ibm.com>
Subject Re: Using grammarpool with included schemas
Date Fri, 07 Jul 2006 05:12:20 GMT
Hi Dick,

An XSGrammar is a collection of schema components for a given target 
namespace. The schema validator will consult the grammar pool once per 
namespace, so you only have one shot to return an XSGrammar object from 
your pool for each namespace. That doesn't prevent your grammar pool 
implementation from doing something clever like merging XSGrammars (see 
org.apache.xerces.impl.xs.XSLoaderImpl.XSGrammarMerger [1]) but that may 
be a bit difficult for you to do particularly if the schemas aren't 
disjoint. I would go the entity resolver route instead of trying that. You 
can register an XMLEntityResolver [2] with the XMLGrammarPreparser by 
calling the setEntityResolver(XMLEntityResolver) method. The parser's 
default behaviour is to open a URLConnection for the location specified. 
If you're unable to create an InputStream from the URLConnection in your 
entity resolver the parser won't succeed at doing that either.



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

Dick Deneer <dick.deneer@donkeydevelopment.com> wrote on 07/04/2006 
01:59:17 PM:

> Hi,
> I am using a grammarpool to cache schemas and want the user to point
> to a number of schemas that will be added to the grammarpool. Then 
> the grammarpool is used to validate a XML instance document. 
> One of the schema (=top )  uses a include to another schema (=sub 
> ).  If I can  rely on the location mentioned in the include there is
> no problem. Just add  "top" to the pool and everything is fine. 
> But when the path in the top schema is invalid, the included schema 
> cannot be found. My first idea was just let the user add the 
> subschema also to the pool. But this has no effect.  The result is 
> that the subschema is just ignored and will not be in the 
> grammarpool (likely caused by the fact that there is already a 
> grammar with the same namespace in the pool, namely "top"). 
> Validation will be incomplete because the type definitions mentioned
> in sub are ignored.
> Working in the other direction (first add the sub, then the top 
> schema) does not not work either: only the sub schema will be added 
> to the grammarpool
> The ideal situation for me would be: just add another schema to the 
> pool if the parser gives an error that something cannot be found.
> Is there no other way then using a entityresolver?
> If so: can I detect in the entityresolver that the schema will or 
> will not be found by the parser.if "not" , I have to return my own 
> inputsource.
> Can I also use such a entityresolver when using a XMLGrammarPreparser?
> PS
> You can easily "replay" the above situations with  
the XMLGrammarBuilder.java 
> program that is supplied with xerces. But also using direct (without
> preparsing) the dom or sax parser with a grammarpool will give the 
> same results.
> I used these xml and schemas
> top.xsd:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:include schemaLocation="include.xsd"/>
> <xsd:element name="myRoot" type="myRootType"/>
> <xsd:complexType name="myRootType">
> <xsd:sequence>
> <xsd:element name="label" type="labelType"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:schema>
> include.xsd:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:simpleType name="labelType">
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="01"/>
> <xsd:enumeration value="02"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:schema>
> instance.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <myRoot>
>     <label>028</label>
> </myRoot>

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

View raw message