Hi Mukul, Mukul Gandhi <[email protected]> wrote on 05/14/2009 12:31:55 PM:
> Hi all, > Let's say we create a JAXP schema object, > javax.xml.validation.Schema (using > javax.xml.validation.SchemaFactory.newSchema calls). > > Would it be useful, if we provide facility to users, so they can > construct a Xerces schema object, XSModelImpl from a > javax.xml.validation.Schema object? > > For this need, we could provide an additional constructor to the user, > XSModelImpl(Schema schema). > > Is the implementation of this requirement, feasible within Xerces? And > will this facility, provide additional value to the users? It's already possible to do this if a user is willing to dive into internals: // Must be Xerces' implementation SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema s = sf.newSchema(new StreamSource(...)); XSGrammarPoolContainer poolContainer = (XSGrammarPoolContainer) s; XMLGrammarPool pool = poolContainer.getGrammarPool(); Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA); XSGrammar [] xsGrammars = ...; ... xsGrammars[0].toXSModel(xsGrammars); In general you can't convert a Schema into an XSModel because it may not come from Xerces and may not even be a Schema for a W3C XML Schema (i.e. could be Relax NG, Schematron or something else). Even with Xerces you can't construct XSModels directly from certain Schema objects, specifically the one returned from SchemaFactory.newSchema() (i.e. the factory method with no args) which caches based on the schema locations specified in the documents that it validates and may throw out some of these grammar objects over time in response to demand for memory. The user can always get the effective XSModel by retrieving it from the PSVI [1] of the documents they validate. > -- > Regards, > Mukul Gandhi > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] Thanks. [1] http://xerces.apache.org/xerces2-j/javadocs/xs/org/apache/xerces/xs/ElementPSVI.html#getSchemaInformation() Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [email protected] E-mail: [email protected]
