Prev Next

Java / JAXB

Could not find what you were looking for? send us the question and we would be happy to answer your question.

What is 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.

Explain the JAXB architecture.

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.

What is Unmarshalling in JAXB?

Unmarshalling refers to the process of converting XML data into JAXB-derived Java objects.

What is marshalling in JAXB?

Marshalling provides a client application the ability to convert a JAXB-derived Java object tree into XML data.

What is the default encoding for generating XML in JAXB?

UTF-8.

What is XML binding in JAXB?

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.

Difference between DTD and XML Schema.

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.

Difference between JAXB and DOM/SAX.

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.

Difference between JAXP and JAXB.

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.

Steps involved in JAXB marshaling or Java object to XML conversion.
  • 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.
«
»
JMX

Comments & Discussions