Hey all, I'm using JAXP to obtain a DOM parser implementation. I'd like to avoid specifying the XSD in the schemaLocation attribute of the XML document and specify the XSD that the parser should use at runtime. Any ideas on how this can be done? Thanks, John
Author and all-around good cowpoke
Joined: Mar 22, 2000
I think you can supply a custom EntityResolver to the parser that will let you intercept all calls for external entities such as DTDs. Look at the DocumentBuilder API for setEntityResolver. Bill
Schemas are more flexible. The schema specification specifically allows for a variety of different means for associating documents with schemas. For instance, one possibility is that both the name of the document to validate and the name of the schema to validate it against could be passed to the validator program on the command line like this: C:\>validator greeting.xml greeting.xsd Parsers could also let you choose the schema by setting a SAX property or an environment variable. Many other schemes are possible. The schema specification does not mandate any one way of doing this. However, it does define one particular way to associate a document with a schema. As with DOCTYPE declarations and DTDs, this requires modifying the instance document to point to the schema. The difference is that with schemas, unlike with DTDs, this is not the only way to do it. Parser vendors are free to develop other mechanisms if they want to.
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.