What is Xsd2Jibx?

Xsd2Jibx gives you a way to generate an initial set of Java classes, and the corresponding JiBX binding definition, from a W3C XML Schema input document. The generated classes and binding give you a starting point for working with XML documents matching the schema, which you can then refactor as appropriate to suit your needs.

The big difference from other data binding frameworks that generate code from schemas is that in the Xsd2Jibx case the generated code is under your control. You can modify the code, changing the binding definition if necessary, while continuing to work with documents matching the original schema. You can also keep working with the original generated classes even as the schema evolves, so long as you can compensate for the schema changes in the binding definition.

Xsd2Jibx is lagging behind the current JiBX code, and the generated bindings are not representative of current best practices. A replacement for Xsd2Jibx is being developed as part of the JiBX 1.2 release.

Current features

The current Beta 0.2b release is a trivial update of the prior Beta 0.2a release, intended only to make the distribution compatible with the latest JiBX distributions. Features supported by the current release include:

  • Generates source code of JavaBean-style classes for complex types
  • Supports element, attribute, group, and attributeGroup references
  • <import> and <include> of local files (relative paths)
  • Inheritance, with complex types that extend other complex types
  • Namespace support, with multiple namespaces and associated packages allowed
  • Multiple schema files as input

Limitations of the Beta 0.2b release are:

  • No enumeration support, and no restriction or validation support
  • No support for xs:any and xs:anyType
  • Prohibited attributes not supported
  • Does not handle an anonymous sequence as a choice (though this can be bypassed by converting it to a complex type)
  • Throws an exception with a "type not yet supported" error when a repeated element with a complex type is the only component of a sequence

Changes since Beta 0.2:

  • Build with JiBX RC1 for runtime compatibility with RC1 and later JiBX releases
  • Fixed generated binding problem with untyped values in collections
  • Corrected issue with improper use of abstract="true" on mappings

Running Xsd2Jibx

The easiest way to set up Xsd2Jibx for use is to copy the jibx-run.jar and xpp3.jar files from the lib directory of your JiBX installation to the lib directory of your Xsd2Jibx installation. Once you've done this you can run the Xsd2Jibx tool from the console using a command of the form (on Unix/Linux; you'll need to change the path and directory separators for Windows):

java -jar xsd2jibx-root/lib/xsd2jibx.jar [options] schema1.xsd schema2.xsd ...

where xsd2jibx-root is the path to the root directory of your Xsd2Jibx installation, the table below gives the options supported by the tool, and the schema#.xsd files are the one or more schemas to be used to generate Java code.

Option Description
-d directory Base directory for code generation.
-n package Package used for code generation from no-namespace schema.
-p uri-lead=pkg-lead Path substitution for going from schema namespace to target package. Xsd2Jibx uses a standard algorithm based on the form of the namespace URI by default, but you can use this option to specify a replacement to change the package used for the code corresponding to a particular schema. If the "uri-lead" portion matches the start of a namespace URI, that namespace will be mapped to the "pkg-lead" portion. URI components following the "uri-lead" text will be converted as usual.

You can also run Xsd2Jibx without copying the files from the JiBX installation into the Xsd2Jibx installation, but in this case you need to explicitly include the two JiBX jars mentioned above in the classpath along with the xsd2jibx.jar, and need to specify the main Java class as org.jibx.xsd2jibx.Generate.

Future changes

Xsd2Jibx is being replaced by a much more capable tool as part of the JiBX 1.2 release. The replacement code will improve support for schema and take advantage of new features in JiBX, and will also be much more robust than the current code.