File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Specifying XSD to validate against at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Specifying XSD to validate against at runtime" Watch "Specifying XSD to validate against at runtime" New topic
Author

Specifying XSD to validate against at runtime

John Fairbairn
Ranch Hand

Joined: May 30, 2002
Posts: 55
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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
John Fairbairn
Ranch Hand

Joined: May 30, 2002
Posts: 55
Hi Bill,
Found this at the following link: http://java.sun.com/webservices/docs/1.0/tutorial/doc/JAXPDOM9.html
Sample code from link:

Thanks,
John
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
A note from http://www.ibiblio.org/xml/books/bible2/chapters/ch24.html about this issue -
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.

Cheers,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
 
Consider Paul's rocket mass heater.
 
subject: Specifying XSD to validate against at runtime