0

I have a code in which am saving a dataset value to xml. The values in the dataset are coming from an Excel sheet (.xls format). My problem is that if a value is blank or null, it's ignoring it but I want that it should close the tag for it, e.g <test></test> or </test>.

my code is

daAdapter = new OleDbDataAdapter("Select * FROM [KDC Report$]", connection);
System.Data.DataTable dt = new System.Data.DataTable("Assets");
daAdapter.Fill(dt);
DataSet ds = new DataSet("DocumentElement");
ds.Tables.Add(dt);
var memoryStream = new MemoryStream();

using (TextWriter streamWriter = new StreamWriter(memoryStream))
{
    var xmlSerializer = new XmlSerializer(typeof(DataSet));
    xmlSerializer.Serialize(streamWriter, ds);
    Encoding.UTF8.GetString(memoryStream.ToArray());
}

ds.WriteXml("C:\\Development\\MyAppln\\ExcelToXML\\Products.xml");
cchana
  • 4,899
  • 3
  • 33
  • 43
NoviceToProgramming
  • 103
  • 1
  • 3
  • 12

1 Answers1

0

You are serializing a DataSet. With datasets you have no control over the XML that is produced.

If you use your own class with properties for all of the fields, you can use the attributes in the System.Xml.Serialization namespace to control serialization.

Kris Vandermotten
  • 10,111
  • 38
  • 49