O'Reilly logo

Java & XML Data Binding by Brett McLaughlin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Class Generation

Class generation in Castor is similar in operation to both JAXB and Zeus; you use a helper class to pass in a set of XML constraints, and the result is source code that can then be compiled and used in your programs. This section details the constraint models that can be used by Castor, as well as the options that Castor makes available beyond what you have already seen in JAXB.

DTDs

Oddly enough, Castor is exactly the opposite of most available data binding packages. Instead of supporting DTDs and having a fairly immature XML Schema implementation, Castor began with support for XML Schema. Because of the work involved in supporting the ever-changing XML Schema specification, and perhaps because of a lack of interest, Castor has never provided support for class generation from DTDs. If you need to support class generation from DTDs, you will need to use one of the other data binding packages discussed previously.

XML Schema

While DTDs are not supported by Castor, excellent support for XML Schema is included. Because Castor has worked on schemas for quite a while, the project has a rich feature set for dealing with that language. The basic class you will use for schema-to-Java generation is org.exolab.castor.builder.SourceGenerator.

Warning

Castor includes a script, sourceGen.bat and sourceGen (for Windows and Unix, respectively), with the Castor download. However, this script has incorrect paths in it and does not work properly. Instead of using this script, simply ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required