@Override
    public void endElement(final String uri, final String localName, final String qName) throws SAXException {
        if (depth == 2) {
            super.endElement(uri, localName, qName);

            // Check to see if the record is ok?
            boolean recordOk = true;
            if (errorReceiverProxy.getErrorReceiver() instanceof final ErrorStatistics errorStatistics) {
                recordOk = errorStatistics.checkRecord(count) == 0;
            }

            // If the record is ok then fire the contents of the buffer at the
            // next filter in the chain.
            if (recordOk) {
                if (!hasOutputRoot) {
                    hasOutputRoot = true;
                    rootEvents.fire(getFilter());
                }

                stopBuffer(getFilter());

                // We have output a record so increase the record count.
                count++;
            }

            // Clear the buffer and prepare to store more SAX events.
            startBuffer();

        } else if (depth > 2) {
            super.endElement(uri, localName, qName);
        }

        depth--;
    }
Fired on an end element.

@param uri       the Namespace URI, or the empty string if the element has no
                 Namespace URI or if Namespace processing is not being
                 performed
@param localName the local name (without prefix), or the empty string if
                 Namespace processing is not being performed
@param qName     the qualified XML name (with prefix), or the empty string if
                 qualified names are not available
@throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception
stroom-pipeline/src/main/java/stroom/pipeline/filter/RecordOutputFilter.java