@Override
    public void endElement(final String uri, final String localName, final String qName) throws SAXException {

        LOGGER.debug("End Element: " + localName + ", Depth: " + depth + ": MergeStarted: " + mergeContainerStarted);

        if (depth > mergeDepth && mergeContainerStarted) {
            LOGGER.debug("Ending Merge Element: " + localName);
            super.endElement(uri, localName, qName);
            // this may be an issue where merge depth is 0
        } else if (depth == mergeDepth - 1 && mergeContainerStarted) {
            LOGGER.debug("Adding final EndElement: " + localName);
            super.endElement(mergeContainerURI, mergeContainerLocalName, mergeContainerQName);
            super.endElement(uri, localName, qName);
            mergeContainerStarted = false;
        } else if (mergeContainerStarted
                   && uri.equals(mergeContainerURI)
                   && localName.equals(mergeContainerLocalName)
                   && qName.equals(mergeContainerQName)) {
            // Do nothing.
            LOGGER.debug("Skipping over Element: " + localName);
        } else {
            super.endElement(uri, localName, qName);
        }
        depth--;
    }
@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 name (with prefix), or the empty string if
                 qualified names are not available
@param atts      the attributes attached to the element. If there are no
                 attributes, it shall be an empty Attributes object. The value
                 of this object after startElement returns is undefined
@throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception
@see #endElement
@see org.xml.sax.Attributes
@see org.xml.sax.helpers.AttributesImpl
@see stroom.pipeline.filter.AbstractXMLFilter#startElement(java.lang.String,
java.lang.String, java.lang.String, org.xml.sax.Attributes)
stroom-pipeline/src/main/java/stroom/pipeline/filter/MergeFilter.java