XML data binding: Difference between revisions

Content deleted Content added
gremlins
Bender the Bot (talk | contribs)
 
(175 intermediate revisions by more than 100 users not shown)
Line 1:
{{one source|date=June 2015}}
'''XML data binding''' refers to the process of representing the information in an [[XML]] document as an [[Object (computer science)|object]] in computer memory. This allows [[Application software|applications]] to access the data in the XML from the object rather than using the [[Document Object Model|DOM]] to retrieve the data from a direct representation of the XML itself.
'''XML data binding''' refers to a means of representing information in an [[XML]] document as a [[business object]] in computer memory. This allows [[Application software|applications]] to access the data in the XML from the object, rather than using the [[Document Object Model|DOM]] or [[Simple API for XML|SAX]] to retrieve the data from a direct representation of the XML itself.
 
It makes it possible to read and write [[XML]] data using a programming language class library (e.g. [[C++]], [[C Sharp (programming language)|C#]], [[Java (programming language)|Java]]), specifically created for a given XML data format.<ref>[https://www.liquid-technologies.com/xml-data-binder/what-is-xml-data-binding-part-1 "What is XML Data Binding - Tutorial"] Liquid Technologies. Retrieved 2024-07-24.</ref> Whilst it is possible to manually write a computer program to achieve this, '''XML data binding''' tools generate the source code to perform these tasks.
An XML data binder accomplishes this by creating a mapping between elements of the [[XML schema]] of the document we wish to bind and [[Instance variable|members]] of a [[Class (computer science)|class]] to be represented in memory.
 
==Description==
When this process is applied to convert an XML document to an object, it is called [[Serialization|unmarshalling]]. The reverse process, to serialize an object as XML, is called marshalling.
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 [[Instance variable|members]] of a [[Class (computer science)|class]] to be represented in memory.
 
When this process is applied to convert an XML document to an object, it is called [[Serialization|unmarshalling]] (also called deserialization). The reverse process, to serialize an object as XML, is called [[marshalling (computer science)|marshalling]].
Since XML is inherently sequential and objects are (usually) not, XML data binding mappings often fail to preserve all the information in an XML document. Specifically, information like [[comment]]s, [[XML entity reference]]s, and [[sibling order]] will 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.
 
Approaches to data binding can be distinguished as follows:
==O/RM frameworks and tools==
 
* '''XML schema based:''' Based on an existing XML schema, classes that correspond to the schema are generated.
===Commercial===
* '''Class based:''' Based on a set of classes to be serialized, a corresponding XML schema is generated.
* [http://www.liquid-technologies.com/ Liquid XML 2006], advanced Wizard driven data binding tool for generating C++, C# .Net, Java and Visual Basic 6 components from XSD, XDR and DTD Schema files.
* '''Mapping-based:''' A mapping description, usually itself an XML document, describes how an existing XML schema maps to a set of classes, and vice versa.
 
===Java=Difficulties==
*[[JAXB|Java Architecture for XML Binding (JAXB)]], and [[JaxMe]] variation
*[[Eclipse (software)|Eclipse Modeling Framework (EMF)]] [http://www.eclipse.org/emf], open source (EPL), dynamic and static binding
*[[XMLBeans]] data binding over [[Document Object Model]] view of data
*[http://hydrate.sourceforge.net/ Hydrate], open source (GNU LGPL), relational/object/XML mapping tool
*[[Castor (software)|Castor]] [http://www.castor.org/license.html], open source (original BSD), object/XML/relational mapping tool
*[[JiBX]] [http://jibx.sourceforge.net], open source (modified BSD), a high performance Java/XML binding framework
*[http://cookxml.sourceforge.net/ CookXml], open source (MIT License), dynamically configurable XML binding tool.
 
Since XML is a document-oriented format and objects are (usually) not document-oriented, simple XML data binding mappings may ignore some of the structural information embedded in an XML document. Specifically, information such as [[comment (computer programming)|comment]]s, XML entity references, and sibling order may not be preserved in the object representation created by the binding application. However, this is not always the case; sufficiently powerful XML data binding tools are capable of preserving 100% of the information stored in an XML document.
===JavaScript===
*[[OpenLaszlo]] [http://www.openlaszlo.org], open source, [[JavaScript]] based, [[Rich Internet application|rich Internet application]] programming language
 
Similarly, since objects residing in computer memory are not inherently sequentially stored, and may include links to other objects (including self-referential links), simple XML data binding mappings may not be capable of preserving all the information about an object when it is marshalled to XML. However, sufficiently powerful data binding tools perform graph structure analysis on objects residing in memory to marshall (cyclic) object graph structures in XML by utilizing standard XML reference attributes.
===.Net===
*Integrated into the language via the .Net attributes: <code>System.Xml.Serialization.XmlRootAttribute</code> and <code>System.Xml.Serialization.XmlElementAttribute</code>
 
===Delphi=Alternatives==
*Integrated into the language via the XML Data Binding Wizard, which can generate appropriate classes and interfaces
from either an example XML file or XSD schema.
 
An alternative approach to automatic data binding relies instead on hand-crafted [[XPath]] expressions that extract data from XML. This approach has some benefits but also has some drawbacks. First, the approach 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. 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, which is time-consuming, potentially error-prone, and hampers application maintenance when XML schemas and XML content models are updated. Another drawback is the lack of XML schema verification, which XML data bindings typically apply automatically during unmarshalling. Schema validity is typically required in secure applications.
===C++===
 
* [http://codesynthesis.com/products/xsd/ CodeSynthesis XSD - XML Data Binding Compiler for C++], open source data binding tool that provides an event-driven, SAX-like C++ mapping in addition to the standard, tree-like in-memory representation
==Data binding in general==
* [http://tech-know-ware.com/lmx/ LMX - XML to C++ Data Binding Code Generator] Convert XML Schema to C++ code for easy interfacing to XML data.
One of XML data binding's strengths is the ability to [[serialization|deserialize]] objects across programs, languages, and platforms.<ref>[https://www.ibm.com/docs/en/odm/8.12.0?topic=binding-what-is-xml "What is XML binding"] IBM. Retrieved 2024-04-16.</ref> 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 [[GNU Octave|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.
* [http://xmlbeansxx.touk.pl/ xmlbeansxx] - a C++ library for easing the processing of XML data. It is very similar to and in fact was inspired by [http://xmlbeans.apache.org Apache XMLBeans] (by The Apache Xml Project).
 
==XML data binding frameworks==
 
{|class="wikitable sortable" style="font-size: 85%; text-align: center; width: 100%;"
|-
! Name
! Programming Language
! License
! First release
! Last stable release
! Code generation from XSD
! Custom mapping
! Note
|-
| [[Apache Commons]] Betwixt
| Java
| {{free|[[Apache License|Apache]]}}
| {{start date|2003|01|28}}
| 0.8
| {{unk}}
| {{unk}}
| Dormant. Serializes objects to XML without requiring an XML schema definition
|-
| [[Apache XMLBeans]]
| Java
| {{free|[[Apache License 2.0]]}}
|
| 5.1.1, {{start date|2022|08|29}}
| {{yes}}
| {{unk}}
|
|-
| [[Castor (framework)|Castor]]
| Java
| {{free|[[Apache License|Apache 2.0]]}}
|
| 1.4.1, {{start date|2016|05|15}}
| {{unk}}
| {{unk}}
| Earlier versions also supported Java-to-SQL persistence but this has since been forked into a separate project
|-
| [[CodeSynthesis XSD]]
| [[C++]]
| {{GPL-lic}} and proprietary
|
| 4.0.0, {{start date|2014|07|22}}
| {{unk}}
| {{unk}}
| with SAX or tree-like mapping into C++ classes
|-
| [[gSOAP]]
| [[C (programming language)|C]] and [[C++]]
| {{GPL-lic}} and proprietary
| {{Start date and age|2000|12|08}}
| 2.8.131, {{start date|2023|09|23}}
| {{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
| {{free|[[BSD License]]}}
|
| 1.2.6, {{start date|2015|01|01}}
| {{yes}}
| {{yes}}
| Maps classes to XML schemas via bytecode manipulation
|-
|[[Liquid XML Studio|Liquid XML Data Binder]]
|C++, C#, Java, Visual Basic.Net, Visual Basic 6 (COM)
|Freeware and proprietry
|{{Start date and age|2001|6|1}}
|{{Start date and age|2024|06|18}}
|{{Yes}}
|{{Yes}}
|Supports XML schema (XSD), DTD, XDR, WSDL. Serializes XML to JSON and JSON to XML.
|-
|[[Liquid XML Studio|Liquid XML Objects]]
|C# and Visual Basic .Net (Supports XSD 1.1)
|Freeware and proprietry
|{{Start date and age|2019|03|03}}
|{{Start date and age|2024|06|18}}
|{{Yes}}
|{{Yes}}
|Direct replacement for XSD.exe. Integrated within [[Visual Studio|Microsoft Visual Studio]]. Supports XML schema (XSD 1.0 and XSD 1.1), DTD, WSDL. Serializes XML to JSON and JSON to XML.
|-
| [https://simple.sourceforge.net/ Simple]
| Java
| {{free|[[Apache License|Apache 2.0]]}}
|
| 2.7.1, {{start date|2017|02|09}}
| {{no}}
| {{yes}}
|
|-
| System.Xml.Serialization
| C#
| ?
|
|
| {{yes}}
| {{no}}
| Part of the .NET framework, contains XML data binding classes; includes <code>xsd.exe</code> tool to generate classes from XSD schema
|-
| [[xmlbeansxx]]
| C++
| {{free|[[Apache License|Apache 2.0]]}}
|
| 0.9.1, {{start date|2008|04|01}}
| {{unk}}
| {{unk}}
| C++ port of Apache XMLBeans
|-
| [[XStream]]
| Java
| {{free|[[BSD license|BSD]]-style license}}
| {{Start date and age|2004|01|01}}
| 1.4.10, {{start date|2017|05|23}}
| {{unk}}
| {{unk}}
| Also capable of serializing to JSON
|-
| [http://zeus.ow2.org/ Zeus] {{Webarchive|url=https://web.archive.org/web/20190128101400/http://zeus.ow2.org/ |date=2019-01-28 }}
| Java
| ?
|
| 3.5 beta, {{start date|2002|08|16}}
| {{unk}}
| {{unk}}
|
|}
 
==See also==
*[[Bound control]]
*[[Data structure]]
*[[JSON]]
*[[LDX+]]
*[[Serialization]]
*[[YAML]]
 
==References==
<!--- See [[Wikipedia:Footnotes]] on how to create references using <ref></ref> tags which will then appear here automatically -->
{{Reflist|30em}}
 
==External links==
*[http://www.rpbourret.com/xml/XMLDataBinding.htm XML Data Binding Resources], by Ronald Bourret
*[http://www.xmlw3.com/pub/aorg/2002/07/24ws/databinding.html?page=1 XML Data-Binding:Schema ComparingPatterns Castorfor toDatabinding .NETWorking Group], by Niel Bornstein
*[https://bindmark.dev.java.net Bindmark project] compares the time and memory performance of XML-Java binding solutions.
*[http://www-128.ibm.com/developerworks/library/x-databdopt/ XML and Java technologies: Data binding, Part 2: Performance], by Dennis Sosnoski, 01 Jan 2003
*[http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/ W3C XML Schema to Standard C++ Data Binding Specification]
*[http://www.codesynthesis.com/projects/xsdbench/ XSDBench XML Schema Benchmark] - compares the performance of validating XML parsers and binding tools
 
[[Category:Programming constructs]]
[[Category:XML]]