Skip to main content

"Schemalet" for easily specifying global and schema bindings

Posted by kohsuke on April 6, 2006 at 9:40 AM PDT

Often, the only JAXB customizations that you need to use are globalBindings and schemaBindings so that, for example, you can set a package, etc.

Now, specifying these cusotmiztions inline in schema is pretty straight-forward, but doing so externally (which you have to do if you don't want to change the schema) is more work. Normally, the way you specify these bindings externally is to write something like this:

<binding xmlns=''><br />   <binding schemaLocation="a.xsd"><br />     <schemaBindings> ... </schemaBindings><br />   </binding><br />   <binding schemaLocation="b.xsd"><br />     <globalBindings ... /><br />   </binding><br /></binding><br />

In particular, it needs to refer to schema files you are compiling, so every time you use JAXB for different places, you need to tweak this file. That's where the idea of what I call "schemalet" comes in for a rescue.

The idea is that, since one can split definitions of one namespace into multiple schema files, instead of trying to attach a customization to an existing schema, you can just write a new "tiny" schema file that just has the customization, like this:

<xs:schema xmlns:xs="" xmlns:jaxb="" jaxb:version="2.0"><br />  <xs:annotation><xs:appinfo><br />    <jaxb:globalBindings ... /><br />  </xs:appinfo></xs:annotation><br /></xs:schema><br />

You can then save this file as "mycustomization.schemalet" (or any other name you like --- file extension doesn't matter), and then submit this to XJC along with your real schemas:

$ xjc ... a.xsd b.xsd c.xsd mycustomization.schemalet

Eventually the right thing to do is to expand the customization syntax, but for now, for some people, this might work handy.

Related Topics >>