This is a migrated thread and some comments may be shown as answers.

Export ToExcelML and forbidden XML characters

1 Answer 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jacques
Top achievements
Rank 1
Jacques asked on 01 Dec 2011, 07:23 PM
I use the export facility to produce XML Excel file.
It happens that some of my data is text containing the & or < characters.
These characters are output in the exported content.
This makes an invalid XML content because these characters are XML key syntax markers that must be be escaped in the XML (&amp; and &lt;).
Is there a way to produce valid XML even when the & and < characters are encountered?

1 Answer, 1 is accepted

Sort by
0
Jacques
Top achievements
Rank 1
answered on 02 Dec 2011, 10:23 AM
I found a solution in a previous forum message.
The ElementExporting event will call :
private void myRadGridView_ElementExporting(object sender, Telerik.Windows.Controls.GridViewElementExportingEventArgs e)
{
    if (e.Value != null && e.Value.GetType() == typeof(string))
    {
        e.Value = (e.Value as string).Replace("&", "&amp;");
        e.Value = (e.Value as string).Replace("<", "&lt;");
    }
}

Tags
GridView
Asked by
Jacques
Top achievements
Rank 1
Answers by
Jacques
Top achievements
Rank 1
Share this question
or