JiBX is a framework for binding XML data to Java objects. It lets you work with data from XML documents using your own class structures. The JiBX framework handles all the details of converting your data to and from XML based on your instructions. JiBX is designed to perform the translation between internal data structures and XML with very high efficiency, but still allows you a high degree of control over the translation process.
How does it manage this? JiBX uses binding definition documents to define the rules for how your Java objects are converted to or from XML (the binding). At some point after you’ve compiled your source code into class files you execute the first part of the JiBX framework, the binding compiler. This compiler enhances binary class files produced by the Java compiler, adding code to handle converting instances of the classes to or from XML. After running the binding compiler you can continue the normal steps you take in assembling your application (such as building jar files, etc.). You can also skip the binding compiler as a separate step and instead bind classes directly at runtime, though this approach has some drawbacks.
The second part of the JiBX framework is the binding runtime. The enhanced class files generated by the binding compiler use this runtime component both for actually building objects from an XML input document (called unmarshalling, in data binding terms) and for generating an XML output document from objects (called marshalling). The runtime uses a parser implementing the XMLPull API for handling input documents, but is otherwise self-contained.
This approach gives several important benefits:
- Flexibility – Use any class structure you want, so long as you can tell JiBX how to translate it to and from XML.
- Performance – Pull parsing and class file enhancement techniques let JiBX build high-performance marshalling and unmarshalling code directly into your classes.
- Clean code – You write the code and JiBX works with it, not the other way around!
For an outside opinion of how JiBX performance stacks up against other Java XML serialization and data binding frameworks, you can view the results of the BindMark tests, along with a similar study focused around Web services performance..
You can also see the earlier performance study by JiBX author Dennis Sosnoski, Data Binding, Part 2: Performance, on the IBM developerWorks XML Zone. Besides these performance issues, Dennis has also covered the JiBX 1.X code generation architecture, and several aspects of the JiBX 2.0 design, in his developerWorks Java Classworking Toolkit column.
XML data binding
XML data binding refers to the process of representing the information in an XML document as an object in computer memory. This allows applications to access the data in the XML from the object rather than using the DOM to retrieve the data from a direct representation of the XML itself.
When this process is applied to convert an XML document to an object, it is called unmarshalling. The reverse process, to serialize an object as XML, is called marshalling.
Since XML is inherently sequential and objects are (usually) not, XML data binding mappings often have difficulty preserving all the information in an XML document. Specifically, information like comments, XML entity references, and sibling order may fail to be preserved in the object representation created by the binding application. This is not always the case; sufficiently complex data binders are capable of preserving 100% of the information in an XML document.
Similarly, since objects in computer memory are not inherently sequential, and may include links to other objects (including self-referential links), XML data binding mappings often have difficulty preserving all the information about an object when it is marshalled to XML.
An alternative approach to automatic data binding relies instead on manually hand-crafted XPath expressions that extract the data from XML. This approach has a number of benefits. First, the data binding code only needs proximate knowledge (e.g., topology, tag names, etc.) of the XML tree structure, which developers can determine by looking at the XML data; XML schemas are no longer mandatory. Furthermore, XPath allows the application to bind the relevant data items and filter out everything else, avoiding the unnecessary processing that would be required to completely unmarshall the entire XML document. The major drawback of this approach is the lack of automation in implementing the object model and XPath expressions. Instead the application developers have to create these artifacts manually.
Data binding in general
One of XML data binding’s strengths is the ability to un/serialize objects across programs, languages, and platforms. You can dump a time series of structured objects from a datalogger written in C on an embedded processor, bring it across the network to process in perl and finally visualize in Mathematica. The structure and the data remain consistent and coherent throughout the journey, and no custom formats or parsing is required. This is not unique to XML. YAML, for example, is emerging as a powerful data binding alternative to XML. JSON (which can be regarded as a subset of YAML) is often suitable for lightweight or restricted applications.
Data binding frameworks and tools
- Liquid XML 2008, advanced Wizard driven data binding tool for generating C++, C# .Net, Java, VB .Net and Visual Basic 6 components from XSD, XDR and DTD Schema files.
- Schemaless Java-XML data binding with XPath and VTD-XML
- Java Architecture for XML Binding (JAXB), and JaxMe variation
- Eclipse Modeling Framework (EMF) , open source (EPL), dynamic and static binding
- XMLBeans data binding over Document Object Model view of data
- Hibernate, open source (GNU LGPL), relational/object/XML mapping tool
- Castor, open source (original BSD), object/XML/relational mapping tool
- JiBX, open source (modified BSD), a high performance Java/XML binding framework
- CookXml, open source (MIT License), dynamically configurable XML binding tool.
- XStream, a simple Java library to serialize objects to XML and back again.
- Integrated into the .NET Framework, in the System.Xml.Serialization namespace.
- CodeSynthesis XSD – Open source XML data binding compiler for C++ which provides an event-driven, SAX-like C++ mapping in addition to the standard, tree-like in-memory object model. For closed source use, the company also offers a commercial license.
- CodeSynthesis XSD/e – Open source, validating XML parser/serializer and C++ data binding generator for mobile and embedded systems.
- Codalogic LMX – Convert XML Schema to C++ code for easy interfacing to XML data.
- xmlbeansxx – A C++ library for easing the processing of XML data. It is very similar to and in fact was inspired by XMLBeans.
- csoap – Provides a tool, xsd2c, using which automatic data binding from XML to C can be achieved. It requires a schema as an input.
- XBinder – Generate highly portable C/C++ source code from XML schema or WSDL.
- XML Data Binding Resources, by Ronald Bourret
- W3C XML Schema to Standard C++ Data Binding Specification