I need to export a DataSet to XML but all cells with the DBNull value disappear from the final XML file. DBNull values are in the middle of the table, so columns(in rows with dbnull) shift and deface the entire table.
public static string GetXmlFromDataSet(DataSet ds)
{
try
{
StringWriter sw = new StringWriter();
ds.WriteXml(sw);
string outputXml = sw.ToString();
return outputXml;
}
catch (Exception ex)
{
return ex.ToString();
}
}
Then XslCompiledTransform makes the file readable for MS Excel. But without some of the cells it is unusable. I need help.
I wrote XML parser and it solves this problem. When
DataSet.WriteXMLsawDBNULLvalue in the Dataset, it will not record to the XML file.Standart method
DataSet.WriteXMLhave an propertyXmlWriteMode. If you useXmlWriteMode.WriteSchemaWriteXML method record schema at the top of XML file. But it works if you will convert it XML to DataSet. In my case XML file transforms to Excel by usingXslCompiledTransform, so schema can’t help me.This is code of my solution: