Datasheet
A parser API makes the various parts of an XML document available to your application. You’ll be see-
ing the SAX and DOM APIs in most of the other Apache XML tools, so it’s worth a brief review to make
sure you’ll be comfortable during the rest of the book.
Let's look at a simple application to illustrate the use of the parser APIs. The application uses a parser
API to parse the XML book description and turn it into a JavaBean that represents a book. This book
object is a domain object in an application you’re building. The file Book.java contains the Java code for
the Book JavaBean. This is a straightforward JavaBean that contains the fields needed for a book, along
with getter and setter methods and a toString method:
1: /*
2: *
3: * Book.java
4: *
5: * Example from "Professional XML Development with Apache Tools"
6: *
7: */
8: package com.sauria.apachexml.ch1;
9:
10: public class Book {
11: String title;
12: String author;
13: String isbn;
14: String month;
15: int year;
16: String publisher;
17: String address;
18:
19: public String getAddress() {
20: return address;
21: }
22:
23: public String getAuthor() {
24: return author;
25: }
26:
27: public String getIsbn() {
28: return isbn;
29: }
30:
31: public String getMonth() {
32: return month;
33: }
34:
35: public String getPublisher() {
36: return publisher;
37: }
38:
39: public String getTitle() {
40: return title;
41: }
42:
43: public int getYear() {
7
Xerces
01 543555 Ch01.qxd 11/5/03 9:40 AM Page 7