Jump to content

XML data binding

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Michael-stanton (talk | contribs) at 20:51, 15 November 2019 (See also: Removed pages which are now linked from the list of data binding frameworks). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

XML data binding refers to a means of representing information in an XML document as a business object in computer memory. This allows applications to access the data in the XML from the object rather than using the DOM or SAX to retrieve the data from a direct representation of the XML itself.

Description

An XML data binder accomplishes this by automatically creating a mapping between elements of the XML schema of the document we wish to bind and members of a class to be represented in memory.

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.

Approaches to data binding can be distinguished as follows:

  • XML schema based: Based on an existing XML schema, classes that correspond to the schema are generated.
  • Class based: Based on a set of classes to be serialized, a corresponding XML schema is generated.
  • Mapping-based: A mapping description, usually itself an XML document, describes how en existing XML schema maps to a set of classes, and vice versa.

Difficulties

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.

Alternatives

An alternative approach to automatic data binding relies instead on 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 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 (programming language) on an embedded processor, bring it across the network to process in Perl and finally visualize in Octave. 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.

XML data binding frameworks

Name Programming Language License First release Last stable release Code generation from XSD Custom mapping Note
Apache Commons Betwixt Java Apache January 28, 2003 (2003-01-28) 0.8 Un­known Un­known Dormant. Serializes objects to XML without requiring an XML schema definition
Apache XMLBeans Java Apache License 2.0 3.1.0, March 26, 2019 (2019-03-26) Yes Un­known
Castor Java Apache 2.0 1.4.1, May 15, 2016 (2016-05-15) Un­known Un­known Earlier versions also supported Java-to-SQL persistence but this has since been forked into a separate project
CodeSynthesis XSD C++ GNU GPL and proprietary 4.0.0, July 22, 2014 (2014-07-22) Un­known Un­known with SAX or tree-like mapping into C++ classes
gSOAP C and C++ GNU GPL and proprietary December 8, 2000; 23 years ago (2000-12-08) 2.8.94, October 17, 2019 (2019-10-17) Yes Yes Supports XML schema, WSDL, and SOAP; XML schemas are not required to serialize C/C++ data to XML; custom mapping of XML schema types to C/C++ types via a type mapping file and from C/C++ types to compatible XML schema types by source code annotation
Java Architecture for XML Binding (JAXB) Java ? Yes Yes
JiBX Java BSD License 1.2.6, January 1, 2015 (2015-01-01) Yes Yes Maps classes to XML schemas via bytecode manipulation
Simple Java Apache 2.0 2.7.1, February 9, 2017 (2017-02-09) No Yes
System.Xml.Serialization C# ? Yes No Part of the .NET framework, contains XML data binding classes; includes xsd.exe tool to generate classes from XSD schema
xmlbeansxx C++ Apache 2.0 0.9.1, April 1, 2008 (2008-04-01) Un­known Un­known C++ port of Apache XMLBeans
XStream Java BSD-style license January 1, 2004; 20 years ago (2004-01-01) 1.4.10, May 23, 2017 (2017-05-23) Un­known Un­known Also capable of serializing to JSON
Zeus Java ? 3.5 beta, August 16, 2002 (2002-08-16) Un­known Un­known

See also

References