javaxmlxercesjaxpxerces2-j

Can XSModel object be obtained from a Schema Object?


Using JAXP I can create a Schema object. e.g.

    Path schemaPath = ...;
    
    StreamSource source = new StreamSource(schemaPath.toFile());
    SchemaFactory factory = 
        SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    
    Schema schema = factory.newSchema(source);

I am using Xerces. Is there way to obtain the XSModel (org.apache.xerces.xs.XSModel) corresponding to the schema object?


Solution

  • I'm no expert and I don't understand all the details, but: first find out what the implementation class of the Schema object is; see whether this has a method to extract a Grammar or GrammarPool; see if you can cast the result to a SchemaGrammar; and then the SchemaGrammar.toXSModel() method gives you what you're after.