O'Reilly logo

Java™ Web Services Unleashed by Mark Wutka, Joseph Weber, Arthur Ryman, K. Scott Morrison, Benoît Marchal, Matthias Kloppmann, Steven Haines, Darren Govoni, Francisco Curbera, Frank Cohen, Robert Brunner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required