Level: Intermediate Dennis Sosnoski (dms@sosnoski.com), Lead consultant, Sosnoski Software Associates Ltd
03 Mar 2009 Code generation from XML schema definitions is widely used for all types of XML data exchange, including Web services. Most data-binding tools rigidly structure generated code based on the schema — even aspects of the schema that may be irrelevant to your application. In this tutorial, second in a two-part series, learn how JiBX 1.2 generates cleaner code by doing a better job of interpreting the schema and eliminating unnecessary class clutter. You'll also see how you can customize the generated code to suit your needs better, including customizations that easily eliminate unnecessary components of the schema.
Before you start
About this tutorial
JiBX is a tool for binding XML data to Java™ objects. JiBX data binding has
long been known as the fastest and most flexible approach for binding Java code to
XML. But the complexity of its binding definitions and its limited support for increasingly widely used XML schema definitions have frustrated users at times. Fortunately, the 1.2 version of JiBX goes a long way toward eliminating these issues. In this tutorial, you'll learn about using the new features of JiBX 1.2 to generate Java code easily from XML schema definitions and to read and write XML documents matching the generated schema definitions — all without needing to get into the details of JiBX binding definitions. Part 1 covers the flip side of starting from Java code and generating XML schema definitions.
Objectives
This tutorial guides you through the process of using JiBX to generate Java code from XML schema definitions. You'll first learn how to work with a simple schema and generate a default Java data model matching that schema, then use that data model for reading and writing XML documents. You'll next see how customizations can be used to modify the code generation so it better fits your needs. Finally, you'll move on to a more complex industry-standard schema example and explore the power of customizations to simplify the data model generated for that schema and improve usability. After reading this tutorial and working through the supplied examples, you'll be able to use JiBX to generate customized Java data models for your own schemas.
Prerequisites
To understand this tutorial, you should have at least a basic knowledge of both Java code and XML. You don't need a detailed understanding of XML schema definitions, but some familiarity with schema will help you understand the examples better.
System requirements
To run the examples you need to install:
- Either:
- A recent version of the Apache Ant build tool.
JiBX download and installation instructions are included in the tutorial.
|