Java examples for XML:XML Schema
The JDK provides a tool that can turn schema documents into representative Java class files.
Use the <JDK_HOME>/bin/xjc command-line tool to generate Java bindings for your XML schemas.
xjc -p org.mymodule.chapter20.recipe20_5 patients.xsd
The patients.xsd file looks like the following:
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="patients"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="patient" type="Patient"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="Patient"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="diagnosis" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:integer" use="required"/> </xs:complexType> </xs:schema>
You can get descriptions of all the command-line options by using the tools -help option:
xjc -help