 | Level: Intermediate Dennis Sosnoski, Lead consultant, Sosnoski Software Associates Ltd
03 Mar 2009 XML schema definitions are the basis for many types of data exchanges, including most forms of Web services. But XML Schema is a complex standard, and most tools for creating and modifying schema definitions are not as powerful or easy to use as those for working with Java™ code. The new features of JiBX 1.2 that you'll learn about in this tutorial — Part 1 of a two-part series — let you start from Java code and easily generate quality schema definitions to match your data structures. You can then use the schemas directly, whether you use JiBX data binding or not.
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 XML schema
definitions easily from existing Java code 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 2 covers the flip side of starting from XML schema definitions and generating Java code.
Objectives
This tutorial guides you through the process of using JiBX to generate XML schema
definitions from Java code. You'll first see how to start with a simple Java data
model and generate a default schema matching that model. From that base, you'll learn how you can easily apply a range of customizations to control the actual values used from your Java classes and how they're accessed, whether they are required or optional, names and namespaces used in the XML, and even the generated schema definition's structure. Along the way, you'll see how JiBX adds value to your generated schemas by leveraging your investment in Javadocs to document the schema definition automatically. After reading this tutorial and working through the supplied examples, you will be able to use JiBX to generate quality XML schema definitions from your own Java data-structure classes.
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.
|  |