XML data binding: Difference between revisions

Content deleted Content added
removing and categorizing
Description: added description of different approaches, split Difficulties: and Alternatives: into separate sections
Line 6:
 
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 (computer science)|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 [[comment (computer programming)|comment]]s, 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.