Content Filters

By this point, you may have noticed a problem with the XMLFilter interface. It filters calls from the client application to the parser; however, most events are passed in the opposite direction from the parser to the client application through the various callback interfaces, particularly ContentHandler. XMLFilter is set up exactly backwards for filtering these events. It filters calls from the client application to the parser, but not the much more important calls from the parser to the client application!

It is possible to work around this. First, intercept the handlers passed to methods such as setContentHandler() and setDTDHandler(). Then, replace them with handlers of your own so that your handlers receive the callback events ...

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.