Datasheet

68: book.setAuthor(text);
69: } else if (e.getTagName().equals("isbn")) {
70: book.setIsbn(text);
71: } else if (e.getTagName().equals("month")) {
72: book.setMonth(text);
73: } else if (e.getTagName().equals("year")) {
74: int y = 0;
75: try {
76: y = Integer.parseInt(text);
77: } catch (NumberFormatException nfe) {
78: throw new SAXException("Year must be a number");
79: }
80: book.setYear(y);
81: } else if (e.getTagName().equals("publisher")) {
82: book.setPublisher(text);
83: } else if (e.getTagName().equals("address")) {
84: book.setAddress(text);
85: }
86: }
87: return book;
88: }
89: }
This concludes our review of the SAX and DOM APIs. Now we’re ready to go into the depths of Xerces.
Installing Xerces
Installing Xerces is relatively simple. The first thing you need to do is obtain a Xerces build. You can do
this by going to http://xml.apache.org/dist/xerces-j, where you’ll see a list of the current official Xerces
builds. (You can ignore the Xerces 1.X builds.)
The Xerces build for a particular version of Xerces is divided into three distributions. Let’s use Xerces
2.4.0 as an example. The binary distribution of Xerces 2.4.0 is in a file named Xerces-J-bin.2.4.0.xxx,
where xxx is either .zip or .tar.gz, depending on the kind of compressed archive format you need.
Typically, people on Windows use a .zip file, whereas people on MacOS X, Linux, and UNIX of various
sorts use a .tar.gz file. There are also .xxx.sig files, which are detached PGP signatures of the correspond-
ing .xxx file. So, Xerces-J-bin.2.4.zip.sig contains the signature file for the Xerces-J-bin2.4.zip distribution
file. You can use PGP and the signature file to verify that the contents of the distribution have not been
tampered with.
In addition to the binary distribution, you can download a source distribution, Xerces-J-src.2.4.zip, and a
tools distribution, Xerces-J-tools-2.4.0.zip. You’ll need the tools distribution in order to build the Xerces
documentation.
We’ll focus on installing the binary distribution. Once you’ve downloaded it, unpack it using a zip-file
utility or tar and gzip for the .tar.gz files. Doing so creates a directory called xerces-2.4.0 in either the cur-
rent directory or the directory you specified to your archiving utility. The key files in this directory are
15
Xerces
01 543555 Ch01.qxd 11/5/03 9:40 AM Page 15