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

        // if closing tag "maptile" is detected get the 9 fields of each tile
        if (elementEndName.equalsIgnoreCase("maptile")) {
            for (int i = 0; i < fieldList.size(); i++) {
                tmpTile.setField(i / Tile.WIDTH_FIELDS, i % Tile.WIDTH_FIELDS,
                        fieldList.get(i));
            }

            fieldList.clear();

            // if count = 4 we need to copy this tile three times
            int tileCount = tmpTile.getCount();

            while (tileCount > 1) {
                ITileType tileCopy = new TileType(tmpTile);
                tileList.add(tileCopy);
                tileCount--;
            }

            // finally add tmpTile to tileList
            tileList.add(tmpTile);
        }

        // if closing tag "field" is detected add the 9 field in sequence to the
        // field list
        if (elementEndName.equalsIgnoreCase("field")) {
            fieldList.add(tmpField);
        }
    }