SAXBufferProcessor p = readAsXMLReader(produceFragmentEvent); p.setContentHandler(handler); if (p instanceof LexicalHandler) {
/** * Write the contents of the buffer to a {@link ContentHandler} with errors * report to a {@link ErrorHandler}. * * <p> * If the <code>handler</code> is also an instance of other SAX-based * handlers, such as {@link LexicalHandler}, than corresponding SAX events * will be reported to those handlers. * * @param handler * The ContentHandler to receive SAX events. * @param errorHandler * The ErrorHandler to receive error events. * * @throws SAXException * if a parsing fails and {@link ErrorHandler} throws a {@link SAXException}, * or if {@link ContentHandler} throws a {@link SAXException}. */ public final void writeTo(ContentHandler handler, ErrorHandler errorHandler, boolean produceFragmentEvent) throws SAXException { SAXBufferProcessor p = readAsXMLReader(produceFragmentEvent); p.setContentHandler(handler); if (p instanceof LexicalHandler) { p.setLexicalHandler((LexicalHandler)handler); } if (p instanceof DTDHandler) { p.setDTDHandler((DTDHandler)handler); } p.setErrorHandler(errorHandler); p.process(); }