public void endElement(String namespaceURI, String sName, String qName)
    throws SAXException {
        if (! isParsing) {
            isParsing = false;
            return;
        }
        List xmlElements = (List) xmlElementsMap.get(currentRoot);
        if (xmlElements.get(xmlElements.size()-1).equals(qName)) {
            return;
        } else {
            List subElements = new ArrayList();
            int targetIndex = xmlElements.indexOf(qName);
            int size = xmlElements.size();
            for (int i = targetIndex; i < size; i++) {
                subElements.add(xmlElements.get(targetIndex));
                xmlElements.remove(targetIndex);
            }
            //Save the sub elements as a list.
            xmlElements.add(subElements);
        }
        isParsing = ! qName.equals(currentRoot);
    }