Skip Headers

# JAXB Validation

Previous

Next

TopLink can validate both complete object trees and subtrees against the XML schema that was used to generate the implementation classes. In addition, TopLink will validate both root objects (objects that correspond to the root element of the XML document) and nonroot objects against the schema used to generate the object's implementation class.

When validating an object tree, TopLink performs the following checks (in order):

1. Check that element appears in the document at the specified location.

2. If maxOccurs or minOccurs is specified, check number of elements.

3. If type is specified, check that element value satisfies the type constraints.

4. If a fixed value is specified, check that the element value matches it.

5. If restrictions (length, patterns, enumerations, and so on) are specified, check that the element value satisfies it.

6. If an ID type is specified during a `validateRoot` operation, check that the ID value is unique in the document.

7. If an IDREF type is specified during a `validateRoot` operation, check that the ID referenced exists in the document.

If validation errors are encountered, TopLink stops validating the object tree and creates a `ValidationEvent` object, according to the JAXB specification. If an error occurs in a subobject, TopLink will not validate further down that object's subtree.

For more information on using TopLink XML to perform validation, see "Using TopLink JAXB Compiler Generated Files at Run Time".

For additional information on JAXB and validation, refer to the JAXB specification at `http://java.sun.com/xml/jaxb/`.