public void processBDSax(int windowSize, ConfigGeneral cg, String DBPath) throws SAXException,
            IOException {

        System.out.println("Parser: SAX");

        _threshold = cg.getThreshold();
        String objName = cg.getDbObjectName();

        System.out.print("Starting XML reader...");
        SaxToDom std = new SaxToDom(_bdFile, objName);
        System.out.println("FINISHED!");

        //DataBase db = DataBase.getSingletonObject(true);

        //XMLToTable xmltt = new XMLToTable(DBPath, objName);
        //xmltt.loadXMLToTable();
        
        //usar apenas para procura da melhor estrutura.
        DataBase.getSingletonObject(false).cleanDuplicatesTable();

        StructureSort ss = new StructureSort();
        cg.setConfigStructure(ss.sortStructure(cg.getConfigStructure()));

        _dbSize = std.countObj();

        System.out.println("Elements in DB : " + _dbSize);

        Compare comp = new Compare();

        int numComp = 0;

        double DdbSize = _dbSize;
        double DwSize = windowSize;
        double blockNum = 0;

        if (Math.round(DdbSize / DwSize) < DdbSize / DwSize)
            blockNum = Math.round(DdbSize / DwSize) + 1;
        else
            blockNum = Math.round(DdbSize / DwSize);

        System.out.println("Blocks: " + Math.round(blockNum));
        int block = -1;

        int wSize = windowSize;

        int window1 = 0;// janela em que est� a iteracao (1� grupo de blocos)
        int window2 = 0;// janela em que est� a iteracao (2� grupo de blocos)

        int object1_Index;// indice do objecto1 do par que est� a ser comparado.
        int object2_Index;// indice do objecto2 do par que est� a ser comparado.

        document = std.makeDom(window1 * wSize, window1 * wSize + wSize - 1);
        List<Node> l1 = std.convertDocToNodeList(document);

        document = std.makeDom(window2 * wSize, window2 * wSize + wSize - 1);
        List<Node> l2 = std.convertDocToNodeList(document);

        while (blockNum > window1) {
            // System.out.println("inicio do ciclo w1 " + window1 + " w2 " +
            // window2);

            if (window1 != block) {
                block = window1;
                System.out
                        .println("BLOCK " + new Integer(window1 + 1) + "/" + Math.round(blockNum));
            }

            int l1Size = l1.size();
            int l2Size = l2.size();
            for (int k = 0; l1Size > k; k++) {

                for (int l = 0; l2Size > l; l++) {

                    if (k >= l && window1 == window2) {
                        continue;
                    } else {
                        object1_Index = window1 * windowSize + k;
                        object2_Index = window2 * windowSize + l;
                        comp.compareNodes(object1_Index, object2_Index, cg, l1.get(k), l2.get(l));
                        numComp++;
                    }
                }
            }

            if (blockNum - 1 == window1)
                break;

            if (window2 == blockNum - 1) {

                window1++;// System.out.println("troca de bloco1 " + window1);
                document = std.makeDom(window1 * wSize, window1 * wSize + wSize - 1);
                l1 = std.convertDocToNodeList(document);
                l2 = l1;
                window2 = window1;// System.out.println("troca de bloco2 " +
                // window2);

            } else {

                window2++;// System.out.println("troca de bloco2 " + window2);
                document = std.makeDom(window2 * wSize, window2 * wSize + wSize - 1);
                l2 = std.convertDocToNodeList(document);

            }

        }

        System.out.print("Printing results to file...");
        // escrever o ficheiro
        BufferedWriter outRP = new BufferedWriter(new FileWriter(_resultsPath
                + "/results_pairs.txt", true));
        FH.writeSortedFile(comp.getDup(), outRP, cg.getStorageType());
        System.out.println("FINISHED!");

        System.out.println("Pairs Compared: " + numComp);

        outRP.close();

        //db.closeConnection();
    }