Working with XML Processing

Working with XML Processing

Overview

Aspose.Cells FOSS for Java processes OOXML XML internally using a streaming SAX-based reader for load and a DOM-based writer for save. The XML processing layer handles repair of malformed packages when LoadOptions.setTryRepairXml(true) is set.

Repair Mode

When loading a damaged XLSX file, enable repair mode via LoadOptions to let the loader fix invalid ZIP entries and malformed XML. The setTryRepairXml(true) flag activates XML-level recovery, while setTryRepairPackage(true) handles corrupt ZIP structures:

import com.aspose.cells_foss.LoadIssue;
import com.aspose.cells_foss.LoadOptions;
import com.aspose.cells_foss.Workbook;

LoadOptions options = new LoadOptions();
options.setStrictMode(false);
options.setTryRepairPackage(true);
options.setTryRepairXml(true);

try (Workbook workbook = new Workbook("damaged.xlsx", options)) {
    if (workbook.getLoadDiagnostics().hasRepairs()) {
        for (LoadIssue issue : workbook.getLoadDiagnostics().getIssues()) {
            System.out.println("Repaired: " + issue.getMessage());
        }
    }
    workbook.save("repaired.xlsx");
}

Load Diagnostics

workbook.getLoadDiagnostics() returns a LoadDiagnostics object with:

  • hasRepairs() — returns true if any repairs were made during load
  • getIssues() — returns a list of LoadIssue objects with messages

See Also

 English