XML Object Binder
________ Current version: 3.1 Hosted by SourceForge.net Logo
Menu
Main page
Quick Example
Userguide [PDF]
Download
Tracker
CVS
Description
XOB is an alternative to JAXB, JBind, etc. XOB lets you define interfaces representing XML tags and have them automatically implemented runtime through the use of reflection giving you an object representation of your XML files.
                                                                                      
XOB features:
  • Unmarshals XML files into an XML object structure defined by interfaces.
  • Creates an XML object structure using a factory interface.
  • Validates an XML object structure using DTD or Schema.
  • Marshals an XML object structure into an XML file.
  • Supports namespaces.
  • Generator for generating XML object interfaces from an XML schema.
    • Schema documentatoin tags becomes javadoc for generated interfaces.
  • Extra feature: HTML documentation generator for an XML schema.
  • Contains simple to use Ant tasks for both generators.
  • Allows the user to choose the name of any XML object (interface name) mapping to an XML element, even when using the generator! Or you can let the generator create a name from the element name.

Comparison
Currently I think XOB does more than JAXB. I haven't looked that closely on JBind, but it seems to have a lot more APIs than XOB. There are probably other similar tools out there that I'm not aware of.

The main differences in XOB is:

  • XOB only uses interfaces, there is no generated classes.
  • XOB has a generator that generates from a schema, but can also be used manually without the generator.

XOB is designed to be straight forward and simple to use. It also takes a different approach by only needing interfaces. All interfaces are provided with a generic implementation runtime through the use of the java.lang.reflect.Proxy class. This means less code taking up space in your jar files.

As of version 3.1 this code is distributed under the Apache Software Licence 2.0.

This code was originaly in complete missunderstanding from my part released under the GPL. I never had the intention to limit the use of this library to only open/free products! The Apache guys have made a much more sensible license.


      
Contact
This is currently a one man show. Anybody interested is welcome to join me, it is however not a very large project.

My name is Tommy Svensson and I can be reached at:



Why
Why did I do XOB when there are other alternatives already available ?
  • Because I could not use JAXB due to its license.
  • Because I was not aware of JBind until I was half done!
  • Because XOB is more flexible due to using only interfaces.
  • Because it was fun!
  • Because it was educational!
  • Because I get the job done my way! :-)


Requirements/Dependencies
XOB requires:
  • JDK 1.3 or above.
  • An XML parser implementing JAXP 1.1/1.2.
  • Can plugin non JAXP parsers also.

XOB makes use of the JAXP 1.1 and 1.2 apis. JAXP 1.2 is required for schema validation.

You can however use a non JAXP parser if you create a wrapper for it that implements the xob.XMLParser interface and set and instance of that on the XMLObjectBinder instance. The only catch is that the parser must be able to deliver an org.w3c.dom.Document structure!

Xerces 2.4.0+ implements JAXP 1.2. JDK 1.4 includes the Crimson parser which implements JAXP 1.1. These are the only 2 parsers I've tested with.


History / news
2007-01-01
Version 3.1 released!

New features:

  • Maven2 xobgen plugin
    XOB is now build with maven2, and to make it easier to use with maven2 I made a plugin for running xobgen during the generate-sources phase. See userguide for usage.

2006-01-03
Version 3.0 released!

New features:

  • Filtering
    It is now possible to apply special filters to a binder instance before unmarshalling. When filters are used all the data in the XML file are still read into memory, but element getters return only those elements that match the filter. This means elements can be modified and then marshalled again without loosing any data. See the userguide for more info.
  • Special override of subelement multiplicity in an XMLSchema when using XOBGen to generate interfaces.
    If the schema says there are many of a subelement you can now with an XML comment tell XOBGen that it only returns one element. This is useful in conjunction with filtering where a filter can cause a list of several subelements to always result in only one matching the filter value. This allows you to treat it as if it only returns one.

    Both of these features were added to support a configuration component that reads the same configuration file on several nodes in a cluster, and needed node specific values for certain properties. The node name is supplied as filter value resulting in only one property being returned on each node, but I can specify a per node value in the config XML file.

    Example:

           <myproperty node="node1">abc</myproperty>
           <myproperty node="node2">def</myproperty>
           <myproperty node="node3">ghi</myproperty>
                                                
    Filtering on "node" attribute with filter value "node1" will only return the myproperty element having value "abc".

    Again, see the userguide for more info on how this works. You can also look at the examples/validating/schema/filter example.

  • Jar filenames now contain a version number.
    Upp to now only the distribution zip had a version number in the name. This made it a bit difficult to determine which version of XOB you had when only the jars, like xob.jar is included in a project distribution. Therefore each jar now also contains the version number in the name.
  • Using Ant version lower than 1.6.x no longer works!
    I decided to no longer support older ant versions since it is more trouble than it is worth. I will remove some no longer working and thus unnecessary code to support old ant versions, and also update the userguide to reflect that when I find the time for that.

Bug fixes:

  • Using namespace name in a method name should now work again!
    An element getter method of the following format: get[namespace]_[element]() threw an exception complaining that the returned element did not match the getter.

2005-03-09
Version 2.8 released!

Bug fixes:

    XML Schema parser (used by xobgen and xsddoc):
  • The top level <xsd:annotation><xsd:documentation> tag was not seen unless the prefix was "xs". This was a dumbbug of extracting the documentation before extracting the namespace prefix used, where the prefix defaulted to "xs".
  • xobgen (interface generator):
  • When extending objects that have their names mapped the original unmapped names where used in the extends declaration of the generated interface. This is now fixed.

2004-12-27
Version 2.5 released!

Bug fixes:

    XML Schema parser (used by xobgen and xsddoc):
  • Now extracts attributes even from xs:simpleType.
  • Since xs:complexType with xs:simpleContent extending a primitive type as xs:string for example is treated as if it were defined as a type="xs:string" any attribute definitions were ignored. This is now solved by not having what I have called public and private types mutually exclusive. The parser will still consider this a public type (isPublicType() returning true) but getPrivateType() will also return something if there are attributes defined.
  • xobgen (interface generator):
  • automap option now added to automatically generate maps for all elements not specifically mapped with "map". The generated object interfaces are mapped exactly to the element name of the schema. This solves the problem of not being able to handle element names starting with a capital letter. When no map is available XOB constructs element names from the setter/getter name, but since the setter/getter has the first character after "set/get" capitalized XOB assumes char was a lowercase char to begin with when reversing it to an element name. When mapped however XOB has the full element name and does not need to construct it.

    I'm considering making the automap option default to true in future versions!

2004-04-04
Version 2.4 released! (Version 2.2 and 2.3 were never released as file releases!).

Changes:

  • xobgen and xsddoc now works on Windows! I used "File.separator" in a getResource() path! The javadoc (which I apparently never read!) clearly states that getResource() always uses '/' independent of platform! The actual xob.jar library have been tested on Windows before, but never the generators.
  • Now supports Ant 1.6.0 and above.

    Ant 1.5.4 and below had a bug in the AntClassLoader, it failed to define the package of a class when loading the class, causing getClass().getPackage() to return null even if the class is not packageless. XOB has a point where it needs to know if an XOB interface belongs to a package or not, which failed when XOB classes were loaded by Ants class loader. The workaround to this was to let XOB provide its own class loader and rename XOBGenAntTask to XOBGenAntTaskReal and let a new XOBGenAntTask wrap and load XOBAntTaskReal using the internal class loader.

    Since version 1.6.0 of Ant the class loader bug has been fixed, and the XOB internal class loader no longer needs to be used (and actually have a conflict with the new Ant class loader!). Therefore XOBGenAntTaskReal and XSDDocAntTaskReal should be used for Ant 1.6.0 and above. XSDDocAntTaskReal now detects if it is being run directly as an Ant task or if it is being wrapped, and handles both situations.

  • The type mappings done by xobgen when translating XML Schema types to XOB types are now done using <xobhome>/lib/TypeMap.xml. These mappings can now easily be added to or modified.

2003-08-15
Not having found any more bugs in a while I decided to release version 2.1.

Version 2.1 contains the below mentioned bug fix plus a verification that element names and interface names match when unmarshalling. It throws XOBParseException on mismatch. Before it was possible to unmarshal a wrong XML file without complaints during unmarshal.

2003-07-18
Bug fix: Getting nonexistent attribute (optional and not set) caused a NullPointerException. In all my test cases I never thought of doing something that simple!! I will currently not make a new release. Get the CVS version, it is simple to build. I will make a new release in a while.

2003-07-15
Version 2.0 released.

I'm using strict and simple oldtime version numbering: Bug fixes bump the minor number, new functions bump the major number.

This release contains several bug fixes that were discovered when using XOB in another project with more complex XML files than those used by the examples. There are bug fixes in all 4 jar files.

New feature: The possibility of choosing the interface names. You can call them anything you want! When using the generator there is a "--map elementName objectName" option or a "<map elementName="elementName" objectName="objectName"/> subtag for <xobgen> that allows you to map XML element names to object names. See userguide for more info.

2003-06-23
Version 1.1 released.

A simple, but important bug fix: marshalling of XML objects to XML now does the standard encoding of the [<>&"'] characters.

2003-06-18
Version 1.0 released! This now feels complete. It now contains 4 jar files:
xob.jar
The main jar, the one you need to include in your application if you use XOB.
xobxsd.jar
This is an XML Schema parser suitable for code generation. The next 2 jar files makes use of this one.
xobgen.jar
Generates XOB interfaces from an XML Schema file. Also contains an Ant task for Ant usage.
xsddoc.jar
Generates HTML documentation for an XML Schema file. Also contains an Ant task for Ant usage.
It also contains improved namespace handling. It is no longer necessary to include namespace prefix in setter and getter names even though that is still possible.

Please see the UserGuide for more information.

2003-05-29
Version 0.5 released. I called this release 0.5 due to that it is missing an XSD->Interface generator. It is however usable as is, and I want to use this in another project. The major version number wont reach 1 until the generator is done (and tested).

About testing: The example code doubles as test code and covers all features of XOB. It is however the only testing that has been done so far.

2003-05-03
This is a very new project, that have just started. It will take a while before there be anything useful available.