X-O lite

This project provides a lightweight framework to serialize/deserialize (or marshall/unmarshall) java objects into XML.

One can thing "Yet another Object-to-XML mapping solution" ! The interesting point of this one is that it takes a original approach based on the strong data encapsulation paradigm of Object Oriented (OO) programming.

Parsing/Serializing XML with X-O lite

X-O lite is a thin layer above the Simple API for XML (SAX). It allows using SAX in a Object Oriented world.

Usual solutions defer all the parsing (and the document knowledge) to a 'Handler' class which will automatically fill-in the parsed objects (and, hence, access their internal representation) through some predefined interface or through introspection. The method proposed here will let each object parse it's own data and put it in it's own variables (with helpers reducing this code to the minimum). The parsing of the whole document is achieved by moving the parse control to each java object during the SAX event notification.

Java to XML serialization is also analyzed with emphasis on the symmetry between serialization and deserialization. In a symmetric world, you can build a java object tree from a sequence of SAX events or generate the same sequence of SAX events from the java object tree.

The result is XML-serializable objects that can be used as java serializable objects. You can combine those objects as you wish, the resulting object tree can also be serialized (back and forth) to XML without any extra work required.

Key benefits:

  • Very simple solution applicable for complex real-life XML parsing though it only requires few support classes/interfaces. Objects have just to implement a single interface with 3 method to be XML-serializable.
  • Objects with private variables. Objects have just the knowledge of the data (and they associated XML tags) they own. The API doesn't force an internal representation of data (you can still use Maps, Sets, Trees ...)
  • Same objects can be re-used to be part of many XML document (or be re-used in the same document). The inheritance and composition between objects is naturally supported.
  • No problem to support complex XML schemas (multiple namespaces, substitution groups, abstract classes ...) or complex object graphs.
  • You have full control of the parsing so you can easily hack any part to support 'exotic' features (like case-insensitive parsing, supporting several schemas at the same time, have alias for tags and attributes ...)

Download

Download the distribution bundle containing the libraries (jars), the documentation and examples (and optionally the source code) from the Sourceforge project:

'X-O lite' download page

Another option, if you're using Maven for build, is to just add references to 'X-O lite' project in your POM as explained in the X-O lite 'Maven Metadata' page and let Maven resolve and download all dependencies.

Note: downloading and using 'X-O lite' implies that you agree with the Apache 2 open-source License terms.

Available documentation

Note: this documentation assume that you know what SAX is and the basic usage of it. To know more about SAX itself, go to http://en.wikipedia.org/wiki/Simple_API_for_XML or http://www.saxproject.org/.

  • Philosophy: This document explains the philosophy of the X-O lite.
  • Applicability: Hints to evaluate if X-O lite is a good choice for you.
  • XMLSerializable Implementation: How to implement the XmlSerializable interface in your model objects.
  • Usage: How to use your XmlSerializable model objects to read/write XML.
  • Examples
    • Simple model: simple example showing the key benefits of X-O lite: strict encapsulation, modularity, reuse, inheritance.
    • Graph model: Example of graph model and how to serialize/deserialize it easily from streams in one pass.
    • Recursive model: Example of recursive model mapped to recursive XML (one XML element can contain itself). It also demonstrate how to use object inheritance in both object model and XML schema and the use of a factory to support polymorphism.
    • Model extension: How to extend (in the Object Oriented sense) the preceding example. The extension is done both at the model objects level and at the XML schema definition level without compromising the parsing process.
  • JAXB Comparison: comparison of the X-O lite solution to the 'recursive model' and 'extension' examples implemented with JAXB.

Sourceforge project

This project is hosted by Sourceforge.
The Sourceforge project main page:

http://sourceforge.net/projects/xo-lite

provides access to the projects technical infrastructure (mailing lists, bug tracking, news, releases, SVN repository ...)