I'm working on a data acquisition application and I'd like to implement a save project function using the XML write method of the DataSet class. When I use the primitive types in my datatable (doubles, strings, etc.) the XML write/read is just working great. However, when I added a custom class type column to my datatable, the XML file output would be full of strange lines containing xmlns, URLs, etc. I understand that was caused by the custom class but how can I get rid of them? It makes the entire XML read process extremely slow.
Edit (just a quick sketch):
namespace CustomClassXMLExporterTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Result", typeof(Result));
Result r1 = new Result();
r1.name = "Somebody";
r1.value = 0.1234;
r1.valid = true;
DataRow dr = dt.NewRow();
dr["Name"] = "Somebody";
dr["Result"] = r1;
dt.Rows.Add(dr);
ds.Tables.Add(dt);
ds.WriteXml("C:\\testxml.xml");
}
}
public class Result
{
public double value;
public string name;
public bool valid;
}
}
Output xml:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table1>
<Name>Somebody</Name>
<Result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<value>0.1234</value>
<name>Somebody</name>
<valid>true</valid>
</Result>
</Table1>
</NewDataSet>