• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Specifying XSD to validate against at runtime

 
John Fairbairn
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic