Chapter 3. Processing XML 59

Figure 3-3 SAX application components

To understand how an event-based API can work, consider the sample document in Example 3-1.

Example 3-1 Sample XML document

<?xml version="1.0" encoding="UTF-8"?>
<Customer>
<name>Mary Smith</name>
<membership>10001</membership>
</Customer>
An event-based interface will break the structure of this document down into a series of linear events, such as those shown in Example3-2.

Example 3-2 Sample event breakdown

start document
start element: Customer
start element: name
characters: Mary Smith
end element: name
start element: membership
characters: 10001
end element: membership
end element: Customer
end document
XML
Ap p lic a tio n
SAX API
XML Parser
XML
Document