ExportXML: Empty cells are still exported as empty XML elements

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

@nicolas.realini,

Could you please share your code segment to evaluate your issue precisely and to consequently figure it out (if issue is found) soon. We will check your issue soon.

@Amjad_Sahi

Apologies, I have added the code to the original post. Please note that I am using Aspose.Cells 21.10.2.0, as previous versions do not export the XML correctly.

@nicolas.realini,

Please notice, after an initial test, I am able to reproduce the issue as you mentioned by using your template file and sample code. I found empty cells are exported as empty XML elements via ExportXml. I have logged a ticket with an id “CELLSNET-49759” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

@nicolas.realini,

This is to inform you that we have fixed your issue now. We will provide you the fixed version within the next few days or so after we have performed QA and incorporated other enhancements and fixes.

1 Like

@Amjad_Sahi,

Thank you for the good news. We are looking forward to test the new build once made available to us.

Best,
Nicolas

@nicolas.realini,

Sure, we will keep you posted on it.

@nicolas.realini

The issue is fixed in v21.11.1

Aspose.Cells21.11.1 For .Net2_AuthenticodeSigned.Zip (5.6 MB)
Aspose.Cells21.11.1 For .Net4.0.Zip (5.6 MB)
Aspose.Cells21.11.1 For .NetStandard20.Zip (5.6 MB)

1 Like

@Peyton.Xu, @Amjad_Sahi,

Thank you for the fix. A quick test shows that the file generated is much more similar to what is exported from Excel directly, and the file is correctly validated.

Best Regards,
Nicolas

@nicolas.realini,

It is nice to know that the fix resolves your issue now. Please take your time to evaluate he new fix.

The issues you have found earlier (filed as CELLSNET-49759) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao