Cells Save As XML - Element Names are Not Escaped

Hi, when exporting a Worksheet to an XML document the XML element names are not escaped. Please see the attached zip file for a sample .xlsx and output file. The conversion can be done on the XLSX->XML demo page.

InvalidElementNamesReproduction.zip (7.3 KB)

A simple spreadsheet with this content:

OkColumnName Spaces Are Present Slashes/Too Punc!@#$%^&*()ation
a 1 foo e
b 2 bar d
c 3 baz f

Will give this invalid XML:

<?xml version="1.0" encoding="utf-8"?>
<root>
    <worksheet name="Sheet1">
        <Row index="1">
            <OkColumnName>a</OkColumnName>
            <SpacesArePresent>1</SpacesArePresent>
            <Slashes/Too>foo</Slashes/Too>
            <Punc!@#$%^&*ation>e</Punc!@#$%^&*ation>
        </Row >
        <Row index="2">
            <OkColumnName>b</OkColumnName>
            <SpacesArePresent>2</SpacesArePresent>
            <Slashes/Too>bar</Slashes/Too>
            <Punc!@#$%^&*ation>d</Punc!@#$%^&*ation>
        </Row >
        <Row index="3">
            <OkColumnName>c</OkColumnName>
            <SpacesArePresent>3</SpacesArePresent>
            <Slashes/Too>baz</Slashes/Too>
            <Punc!@#$%^&*ation>f</Punc!@#$%^&*ation>
        </Row >
    </worksheet>
</root>

I’d suggest running candidate element names through the EncodeName function.

Thanks!
-Dave

@DavidP,

Thanks for the template Excel file.

Using the online converter application, I found some elements especially for the last column is not rendered properly. We will look into it soon. But when I tried using our latest version/fix: Aspose.Cells for .NET v22.9 (Download | NuGet), it works absolutely fine, it renders SpreadsheetML (XML) ok.
e.g.
Sample code:

var workbook = new Workbook("e:\\test2\\InvalidXmlElementNamesReproduction.xlsx");
workbook.Save("e:\\test2\\out1.xml");

Please try our latest version and let us know with details if you still find any issue with the output XML file.

Hi Amjad, thanks for the quick followup!

The problems seems to be exclusive to the SaveFormat.Xml style. SaveFormat.SpreadsheetML works OK. Here’s a screenshot of me reproducing the problem in 22.9. XmlDocument throws an exception when I load the file produced with SaveFormat.Xml.

image.png (238.9 KB)

@DavidP,

Thanks for providing further details.

Please notice, I am able to reproduce the issue as you mentioned by using your template file to convert to XML (SaveFormat.Xml). I found some element names are not escaped properly in the output XML file. We will also include fix for the online conversion app.
e.g.
Sample code:

var workbook = new Workbook("e:\\test2\\InvalidXmlElementNamesReproduction.xlsx");
workbook.Save("e:\\test2\\out1.xml",SaveFormat.Xml);

I have logged a ticket with an id “CELLSNET-52071” for your issue. We will look into it soon.

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

1 Like

@DavidP,

This is to inform you that your issue has been resolved. The fix will be included in the next upcoming release (Aspose.Cells for .NET v22.10) which is scheduled in the first/second week of October 2022. You will also be notified when the next version is released.

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