The XMLFilterImpl Class

SAX includes an adapter class that you can subclass to build these sorts of two-way filters: org.xml.sax.helpers.XMLFilterImpl. Its general design is similar to what I just detailed, but it implements all of the relevant interfaces in one class:

public class XMLFilterImpl implements XMLFilter, 
 EntityResolver, DTDHandler, ContentHandler, ErrorHandler

When the various setter methods such as setContentHandler() and setErrorHandler() in this class are invoked, the handler is stored in a private field. For example, here is the setContentHandler() method:

public void setContentHandler (ContentHandler handler) 
{
    contentHandler = handler;
}

When the parse() method is called, it swaps out all of the installed handlers for the ...

Get Processing XML with Java™: A Guide to SAX, DOM, JDOM, JAXP, and TrAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.