@Override
    public void startDocument() throws SAXException {
        //if (LOGGER.isTraceEnabled()) {
        //    LOGGER.trace("startDocument called, buffer [%s]", truncateAndStripWhitespace(getBuffer()));
        //}
        try {
            //clear out the buffer in case we have a lone processing instruction from a previous empty split
            //as the sax processor will write a processing instruction whenever startDocument is called, potentially
            //leading to many of them if we have lots of empty splits before this
            bufferedWriter.flush();
            stringWriter.getBuffer().setLength(0);
        } catch (final IOException e) {
            throw new SAXException(e);
        } finally {
            if (!startedDocument) {
                startedDocument = true;
                handler.startDocument();
                super.startDocument();
            }
        }

    }
Writes out XML and records segment boundaries as it goes.
stroom-pipeline/src/main/java/stroom/pipeline/writer/XMLWriter.java