Java / JAXB
Java Architecture for XML Binding (JAXB) provides a fast and convenient way to bind XML schemas and Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications. JAXB provides methods for unmarshalling (reading) XML instance documents into Java content trees, and then marshalling (writing) Java content trees back into XML instance documents. JAXB also provides a way to generate XML schema from Java objects.
JAXB architecture consists of 3 components.
Schema compiler binds a source schema to a set of schema-derived program elements. The binding is described by an XML-based binding language.
Schema generator maps a set of existing program elements to a derived schema. The mapping is described by program annotations.
Binding runtime framework provides unmarshalling (reading) and marshalling (writing) operations for accessing, manipulating, and validating XML content using either schema-derived or existing program elements.
Unmarshalling refers to the process of converting XML data into JAXB-derived Java objects.
Marshalling provides a client application the ability to convert a JAXB-derived Java object tree into XML data.
UTF-8.
XML binding is the representation of XML document content as an object in computer memory. At compile time, a schema driver processes the XSD and generates an execution object model (XOM). At run time, an XML data driver creates an XML object from the XML document.
DTD is not written using XML while XML schema are xml documents in itself.DTD stands for Document Type definition, a legacy way to define structure of XML documents.
XML schema offers more types to map different types of data in XML documents.
The Java DOM and SAX parsing are lower-level APIs to parse XML documents, while JAXB is a higher-level API for converting XML elements and attributes to a Java object hierarchy (and vice versa). Implementations of JAXB may use a DOM or SAX parser behind the scenes to do the actual parsing of the XML input data.
JAXP (Java API for XML Processing) refers to the outdated low-level XML APIs in JavaSE, such as DOM, SAX and StAX.
JAXB (Java Architecture for XML Binding) uses annotations to bind XML documents to a java object model.
- Create POJO class and add JAXB annotations. Annotate with @XmlRootElement @XmlAccessorType and annotate all fields with @XmlElement. This will bind Object properties to XML elements.
- Create the JAXBContext object.
- Create the Marshaller objects.
- Create the content tree by using set method.
- Invoke the marshal method.