One approach is to create a ContentHandler
that watches for events that signal the entry or exit from a <small>
element. This handler acts as a proxy, and in "normal" mode passes the SAX events straight through to the "real" ContentHandler
.
However, when entry into a <small>
element is detected, the proxy is responsible for the creation of a TransformerHandler
, plumbed up to a DOMResult
. The TransformerHandler
expects all the events that a complete, well-formed document would produce; you cannot immediately send it a startElement
event. Instead, simulate the beginning of a new document by invoking setDocumentLocator
, startDocument
, and other necessary events on the TransformerHandler
instance first.
Then, until the end of the <small>
element element is detected by the proxy, all events are forwarded to this TransformerHandler
instead of the "real" ContentHandler
. When the closing </small>
tag is encountered, the proxy simulates the end of a document by invoking endDocument
on the TransformerHandler
. A DOM is now available as the result of the TransformerHandler
, which contains only the ` fragment.
This process is repeated through the whole, larger document.