---
Product: Aspose.Cells
Platform: net
Page Type: docs
Canonical URL: https://docs.aspose.org/cells/net/developer-guide/working-with-xml-processing
---

# Working with XML Processing

XML processing internals in Aspose.Cells FOSS for .NET: WorkbookXmlMapper, WorksheetXmlMapper, SharedStringTableXmlMapper, StylesheetXmlMapper, and XmlParsingException.

## Overview

XLSX files store their data in XML parts inside an OPC package. Aspose.Cells FOSS for .NET exposes the XML parsing and serialization layer through four mapper classes: `WorkbookXmlMapper`, `WorksheetXmlMapper`, `SharedStringTableXmlMapper`, and `StylesheetXmlMapper`. Each mapper implements both `Read` and `Write` operations for its corresponding XML part. These are internal infrastructure APIs — most application code works entirely through the `Workbook` and `Worksheet` objects.

---

### XML Mapper Classes

Each XML mapper is responsible for one XML part of the XLSX structure:

| Mapper | XML part | Responsibility |
|--------|----------|----------------|
| `WorkbookXmlMapper` | `xl/workbook.xml` | Workbook-level metadata, sheet references, defined names |
| `WorksheetXmlMapper` | `xl/worksheets/sheetN.xml` | Cell data, formulas, hyperlinks, conditional formats, data validation |
| `SharedStringTableXmlMapper` | `xl/sharedStrings.xml` | Shared string table for de-duplicated string values |
| `StylesheetXmlMapper` | `xl/styles.xml` | Cell styles, fonts, fills, borders, number formats |

Each mapper exposes two methods — `Read` and `Write` — invoked by the library's load and save pipelines respectively.

---

### XmlParsingException

`XmlParsingException` is thrown when a mapper encounters malformed XML that cannot be repaired. It is raised before `WorkbookLoadException` in the error hierarchy when the failure occurs during XML parsing specifically.

```csharp
using Aspose.Cells_FOSS;

var opts = new LoadOptions
{
    TryRepairPackage = true,
    TryRepairXml = true,
};

try
{
    var wb = new Workbook("malformed.xlsx", opts);
    Console.WriteLine("Loaded: " + wb.Worksheets.Count + " sheet(s)");
}
catch (XmlParsingException ex)
{
    Console.WriteLine("XML parse error: " + ex.Message);
}
catch (WorkbookLoadException ex)
{
    Console.WriteLine("Load error: " + ex.Message);
}
```

---

### Tips and Best Practices

- Set `TryRepairXml = true` in `LoadOptions` to enable the mapper's fault-tolerant parsing path.
- Catch `XmlParsingException` in addition to `WorkbookLoadException` when handling files from external systems that may produce malformed XML.
- The XML mapper classes are not intended to be instantiated by application code — they are invoked automatically during `Workbook` construction and `Save()`.
- If you need to inspect raw XML content for diagnostics, extract the XLSX as a ZIP and examine the relevant XML parts directly.

---

### Common Issues

| Issue | Cause | Fix |
|-------|-------|-----|
| `XmlParsingException` on load | Malformed XML in one of the XLSX parts | Set `TryRepairXml = true` in `LoadOptions` |
| Missing styles after round-trip | `StylesheetXmlMapper` could not parse a custom style record | Check `LoadDiagnostics.Issues` for style-related repair entries |
| Shared strings missing in loaded file | `SharedStringTableXmlMapper` encountered a corrupt shared string table | Enable `TryRepairXml`; verify original file has a valid `xl/sharedStrings.xml` |

---

### FAQ

#### Can I implement my own XML mapper?

The XML mapper classes are sealed internal infrastructure. Custom mappers are not supported in the current API surface.

#### Why is there a separate `SharedStringTableXmlMapper`?

The OOXML specification separates string values into a shared string table (`xl/sharedStrings.xml`) to de-duplicate repeated strings across the workbook. The mapper handles reading and writing this table independently.

#### Does `TryRepairXml = true` fix all XML problems?

`TryRepairXml` handles recoverable problems such as unclosed elements, missing namespaces, and truncated values. Structurally valid but semantically inconsistent XML (e.g. broken formula references) may still cause `XmlParsingException`.

---

### API Reference Summary

| Class | Description |
|-------|-------------|
| `WorkbookXmlMapper` | Reads/writes `xl/workbook.xml` |
| `WorksheetXmlMapper` | Reads/writes per-sheet XML parts |
| `SharedStringTableXmlMapper` | Reads/writes `xl/sharedStrings.xml` |
| `StylesheetXmlMapper` | Reads/writes `xl/styles.xml` |
| `XmlParsingException` | Thrown on unrecoverable XML parse failures |

## See Also

- [Aspose.Cells for .NET — Enterprise Documentation](https://docs.aspose.com/cells/net/)