private ContentHandler createHandler() {
        ContentHandler handler = null;

        try {
            final ErrorListener errorListener = new ErrorListenerAdaptor(getElementId(), locationFactory,
                    errorReceiver);
            transformerFactory.setErrorListener(errorListener);

            final TransformerHandler th = transformerFactory.newTransformerHandler();
            final Transformer transformer = th.getTransformer();
            transformer.setErrorListener(errorListener);
            XMLUtil.setCommonOutputProperties(transformer, indentOutput);

            // Set the encoding to use.
            Charset charset = StreamUtil.DEFAULT_CHARSET;
            if (encoding != null && !encoding.isEmpty()) {
                try {
                    charset = Charset.forName(encoding);
                } catch (final RuntimeException e) {
                    errorReceiver.log(Severity.ERROR, null, getElementId(),
                            "Unsupported encoding '" + encoding + "', defaulting to UTF-8", e);
                }
            }
            transformer.setOutputProperty(OutputKeys.ENCODING, charset.name());

            th.setResult(new StreamResult(outputStreamWriter));
            th.setDocumentLocator(locator);
            handler = th;
        } catch (final TransformerConfigurationException e) {
            errorReceiver.log(Severity.FATAL_ERROR, null, getElementId(), e.getMessage(), e);
            throw LoggedException.wrap(e);
        }

        return handler;
    }
This filter is used to buffer SAX events in memory if required. Having
buffered SAX events this filter can then fire them at a content handler.
stroom-pipeline/src/main/java/stroom/pipeline/record/XMLRecordEmitter.java