Chapter 4. Consuming SAX2 Events
Most of the power of SAX is exposed through event callbacks. In previous chapters you’ve seen some of the most widely used event callbacks as well as how to ensure that all the callbacks are generated and reported to application code.
This chapter presents the rest of the standard SAX event-handling interfaces (including the extension handlers), then talks about some of the common ways that event consumers use those interfaces. These interfaces are primarily implemented by application code that consumes events and needs to solve particular problems. You might also write custom event producers, which call these interfaces directly rather than expecting some type of XMLReader to issue them.
More About ContentHandler
In Section 2.3, in Chapter 2, we looked at the most important APIs used to handle XML document content. Some other APIs were deferred to this section because they aren’t used as widely. Depending on what problems you’re solving, you may rely heavily on some of these additional methods.
Other ContentHandler Methods
Five ContentHandler callbacks were discussed in Chapter 2: Section 2.3.4 explained how characters and element boundaries were reported, and Section 2.6.4 explained how namespace-prefix scopes were reported. But the interface has five other methods. Here’s what they do and when you’ll want to use them:
-
void setDocumentLocator (Locator l) This is normally the first callback from a parser; the single parameter is a Locator ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access