@Override
    public void startElement(final String uri, final String localName, final String qName, final Attributes atts)
            throws SAXException {
        try {
            // if we are starting an element then we are actually writing XML so
            // switch the handler.
            if (!doneElement) {
                doneElement = true;
                jsonGenerator = createGenerator();
            }

            // If depth is 0 then we are entering an event.
            if (depth == 0) {
                borrowDestinations(null, null);
            }

            // Increase the element depth.
            depth++;

            if (jsonGenerator != null) {
                currentKey = atts.getValue(JSONParser.XML_ATTRIBUTE_KEY);

                if (localName.equals(JSONParser.XML_ELEMENT_MAP)) {
                    elements.push(localName);
                    writeKey();
                    jsonGenerator.writeStartObject();
                } else if (localName.equals(JSONParser.XML_ELEMENT_ARRAY)) {
                    elements.push(localName);
                    writeKey();
                    jsonGenerator.writeStartArray();
                }
            }

        } catch (final IOException | RuntimeException e) {
            error(e);
        } finally {
            content.clear();
            super.startElement(uri, localName, qName, atts);
        }
    }
@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/writer/JSONWriter.java