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

        if (depth == 1) {
            if (secondLevelElementToCreateDocs.equals(localName)) {
                try {
                    contentHandler.endElement(uri, localName, qName);
                    contentHandler.endElement(topLevelUri, topLevelElementToSkip, topLevelQName);

                    contentHandler.endDocument();
                    //Finish new document and extract XPaths
                    // Get the tree.

                    final TinyTree tree = builder.getTree();

                    final List<StringFieldValue> stringFieldValues = new ArrayList<>(xPathExecutables.length);
                    for (int pos = 0; pos < xPathExecutables.length; pos++) {
                        final String fieldName = queryInfoHolder.getFieldIndex().getField(pos);
                        final XPathSelector selector = xPathExecutables[pos].load();

                        selector.setContextItem(new XdmNode(tree.getRootNode()));
                        final Iterator<XdmItem> iterator = selector.iterator();

                        StringBuilder thisVal = new StringBuilder();
                        int numVals = 0;
                        while (iterator.hasNext()) {
                            XdmItem item = iterator.next();
                            numVals = stringifyItem(item, thisVal, numVals);
                        }
                        stringFieldValues.add(new StringFieldValue(fieldName, thisVal.toString()));
                    }
                    fieldListConsumerHolder.acceptStringValues(stringFieldValues);

                } catch (SaxonApiException ex) {
                    log(Severity.ERROR, "Unable to evaluate XPaths", ex);
                } finally {
                    contentHandler = null;
                }
            } else {
                contentHandler = null;
                secondLevelElementToCreateDocs = "";
                log(Severity.ERROR,
                        LogUtil.message("Unable to finding closing tag for {}", secondLevelElementToCreateDocs),
                        null);
            }

        } else if (depth == 0) {
            if (topLevelElementToSkip.equals(localName)) {
                topLevelElementToSkip = "";
            } else {
                topLevelElementToSkip = "";
                log(Severity.ERROR,
                        LogUtil.message("Unable to finding closing tag for {}", topLevelElementToSkip),
                        null);
            }

        } else {
            //Pop element
            contentHandler.endElement(uri, localName, qName);
        }

        super.endElement(uri, localName, qName);
    }
Sets the locator to use when reporting errors.

@param locator The locator to use.
stroom-search/stroom-search-extraction/src/main/java/stroom/search/extraction/XPathExtractionOutputFilter.java