ITWissen.info - Tech know how online

Java architecture for XML binding (JAXB)

JAXB stands for Java Architecture for XMLBinding and names an application programming interface ( API) for interaction between applications programmed in Java and XML documents. JAXB is thus an alternative to well-known technologies such as Simple API for XML( SAX) and Document Object Model( DOM), as it offers more convenient options for writing and reading XML documents directly from the Java application.

In this context one speaks also of "Mapping", and means in this case the direct mapping of object states on XML documents. The framework - the class library - offers methods for the specific manipulation of Java objects and XML documents. Thereby the API automates quasi the process of the transformation in contrast to the function mode of a special XML processor with subsequent transfer of the XML elements on objects or the manual mapping of Java objects on XML documents. Annotations or a special schema file are used to define the rules of the transformation. Annotations determine the elements to be mapped and vice versa a program is generated by the schema file, which independently generates the JavaBeans representing the XML documents. JAXB 2.1 is part of the Java Development Kit( JDK) from version 6.

Relationship between XML and Java

Relationship between XML and Java

The illustration shows first of all on the right side the connection between XML documents and the Java API represented by JAXB. The mutual conversion of the data structures is clearly visible, for which the corresponding Java code of the developer is responsible. In the left part of the figure, the relationship between the XML schema and the Java classes of the API is clear. Here, the schema compiler and schema generator act to transform the data structure description and vice versa. This also shows the four basic functionalities of JAXB - serialization, deserialization, schema generator and schema compiler - which can be used entirely independently.

The JAXB API is a composite of several packages:

  • javax.xml.bind - provides the general core functions such as serialization, deserialization and validation.
  • javax.sml.bind. annotation - defines all annotations valid in JAXB.
  • javax.sml.bind.helpers - summarizes some standard implementations of JAXB interfaces.
  • javax.xml.bind.util - defines JAXB service classes

The following concepts are assumed for understanding the JAXB API:

  • Mapping a data structure to a sequential representation form - that is, writing data to an XML document - is called serialization or marshalling.
  • If a Java object is created starting from an XML document - i.e. an XML document is read - this is referred to as deserialization or unmarshalling.
  • Data binding is the process that leads to a mapping of data (e.g. XML documents) to corresponding objects in memory.

Object creation

For the creation of objects from existing XML documents JAXB provides the appropriate classes and interfaces. Another requirement is the submission of an XML schema that describes in XML syntax the relationships between the elements and attributes of the XML document.

The input of the JAXB Binding Compiler is the XML schema. From it, the code for the JAXB classes is generated, which are then compiled together with the files of the JAXB bundle and the application. Provided that an XML document has been written according to the rules of the XML schema, the JAXB Binding Framework uses unmarshalling to transform it into a tree structure, which then maps the contents of the XML document. The structure tree consists of a set of Java objects that correspond to the instantiated JAXB classes. The structure tree can now be modified by the application. Once this process is complete, the structure tree can be transformed back into an XML document by means of marshalling. Both marshalling and unmarshalling provide the option of validating the data against the XML schema.

The goal of JAXB

The goal of JAXB is to support processing related to XML documents - directly from the Java application. Thereby a developer does not need any knowledge about technologies like Simple API for XML (SAX) or Document Object Model (DOM), but uses simplified the methods provided by JAXB. However, JAXB currently only supports the XML schema for defining the structure of XML documents. This was different in a first version - there the description of the structure in a Document Type Definition( DTD) was assumed. Due to the limitations of the DTD with regard to data types and their values or its poor handling of all formats that do not correspond to text formats, the requirements for validated and consistent XML documents could not be met, so that the XML schema is now used. JAXB is used among other things for the import of configuration files, the generation and manipulation of XML documents, for the validation of user inputs e.g. in a Browser and in connection with a configuration management for the production and care of configuration files.

https://www.jaxb.dev.java.net/

Informations:
Englisch: Java architecture for XML binding - JAXB
Updated at: 09.11.2013
#Words: 811
Links: Java, application programming interface (API), application programming interface (API), interaction, simple API for XML (SAX)
Translations: DE
Sharing:    

All rights reserved DATACOM Buchverlag GmbH © 2024