Hello,
We have noticed that the ExportXML method of Aspose.Cells does not produce the same result as Excel for empty cells; in Excel, if a mapped cell is empty, it is not exported at all, whereas ExportXML always exports the cells as empty XML elements (ex. <XMLElement />
).
This makes the generated XML file invalid against an XSD schema, if the element is defined as having minOccurs=0, because the element exists but is not empty (and this fails validation against the XSD).
Test files (Excel + output from Excel + output from Aspose.Cells + XSD used for validation + XML validation logs): Files.zip (128.0 KB)
Could you check this and let me know if this behavior can somehow be controlled? Ideally, it should work the same as Excel does.
Code:
class Program
{
private const string ResourcesFolder = "Resources";
private const string FileName = "Example.xlsx";
private const string xsdFilename = "xmlMaps.xsd";
private const string xmlFilename = "extractedXML.xml";
static void Main(string[] args)
{
string sourceDir = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), ResourcesFolder);
string path = Path.Combine(sourceDir, FileName);
string xmlPath = Path.Combine(sourceDir, xmlFilename);
GetXmlMapFile(path, xmlPath);
Console.WriteLine("XML extracted to: " + xmlPath);
Console.ReadLine();
}
static void GetXmlMapFile(string filePath, string destination)
{
// Load sample Excel file having XML Map
Workbook wb = new Workbook(filePath);
if (wb.Worksheets.XmlMaps.Count >= 1)
{
XmlMap map = wb.Worksheets.XmlMaps[0];
wb.ExportXml(map.Name, destination);
}
}
}
I used Aspose.Cells 21.10.2.0 (previous versions do not export the XML correctly).
Best Regards,
Nicolas