Motivation
Type Safety
JAXB enables you to work with a type-safe model of XML documents, with Java classes directly corresponding to the types defined in an XML schema.
The JAXB Reference implementation includes a tool called xjc to generate JAXB compliant Java classes from an XML schema. xjc defines a plugin API for custom extensions to modify or enrich the generated Java classes. XVisitor uses this plugin API to support the Visitor pattern for depth-first traversal of JAXB documents.
Separating traversal and application logic
Many applications need to parse XML documents and traverse the document model in one or more passes to extract information from the document.
For each processing step, different actions will have to be executed on different nodes, but the traversal logic for descending from each node to its children is always the same.
The Visitor pattern encapsulates the traversal logic in a central place. The application logic is simply implemented by overriding selected methods of a default no-op Visitor implementation.