Binding an XML Schema to a Class

Using the xjc JAR file in the JAXB lib folder and passing it a DTD and a binding schema performs binding. The xjc JAR file can be used as follows:

java -jar jaxb-xjc-{version} .jar books.dtd books.xjs

The two inputs to the xjc JAR file are the DTD and the binding schema (commonly with the extension xjs). The DTD used for this chapter is shown in Listing 13.1.

Listing 13.1. books.dtd
<!ELEMENT books (book*) >
<!ELEMENT book (title, author, price) >
<!ATTLIST book category CDATA #REQUIRED >
<!ELEMENT title (#PCDATA) >
<!ELEMENT author (#PCDATA) >
<!ELEMENT price (#PCDATA) >

This DTD defines a root <books> node that has zero or more <book> nodes; a sample XML document is shown in Listing 13.2.

Listing 13.2. ...

Get Java™ Web Services Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.