Validating while unmarshalling

However, W3C XML Schema validation can be very costly.

Another possibility is to set up a SAX pipeline in such a way that your XML parser does the validation; alternately, you could install a stand-alone validator in the pipeline.

A Validation Event Handler can explicitly tell a JAXB implementation whether it should reject a document or try to recover from errors.

It also gives you more information, such as line numbers, about errors.

A JAXBContext instance manages the binding relationship between XML element names to Java content interfaces for a JAXB implementation to be used by the unmarshal, marshal and validation operations. This property file must contain a property named bind.context.factory whose value is the name of the class that implements the create Context API.

For example, by using String Writer, you can marshal an object into a string.

The main client entry point into the binding framework is the JAXBContext class. The Unmarshaller class in the bind package provides the client application that contains classes generated by JAXB binding compiler, the ability to convert XML data into a tree of Java content objects.

It provides an abstraction for managing the XML-Java binding information necessary to implement the JAXB binding framework operations: unmarshal, marshal and validate. The unmarshal method for a schema (within a namespace) allows for any global XML element declared in the schema to be unmarshalled as the root of an instance document.

The main package in the JAXB binding framework, xml, is described in more detail below. JAXBContext, it simply has to provide a class that implements the create Context API.

The JAXB API, defined in the bind package, is a set of interfaces through which client applications communicate with code generated from a schema. By allowing for multiple Java packages to be specified, the JAXBContext instance allows for the management of multiple schemas at one time.

Leave a Reply