@Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) {
        currentPre++;
        currentElementPre = currentPre;
        if (rootMatch == null) {
            if (qName.equals(root.getName()) || root.getName().equals("*")) {
                addMatch(qName, root, null);
            } else {
                throw new RuntimeException("Root of the query tree does not correspond with root of the XML document");
            }
        } else {
            //for (TPEStack stack : rootStack.getDescendantStacks()) {
            for (PatternNode node : current.getStack().getPatternNode().getChildren()) {
                if (!node.isAttribute()) {
                    addMatch(qName, node, null);
                }
            }
        }
        for (int i = 0; i < attributes.getLength(); i++) {
            currentPre++;
            String attribute = attributes.getQName(i);
            // similarly look for query nodes possibly matched
            //for (TPEStack s : rootStack.getDescendantStacks()) {
            for (PatternNode node : current.getStack().getPatternNode().getChildren()) {
                if (node.isAttribute()) {
                    addMatch(attribute, node, attributes.getValue(i));
                }
            }
        }
    }