1

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>
JustGreg
  • 231
  • 2
  • 6
  • 17
  • Please post your code and a sample of the resulting XML file. – Wagner DosAnjos Aug 28 '14 at 13:38
  • Please find the updated original post. Thank you! – JustGreg Aug 28 '14 at 13:57
  • One solution might be to use an XmlWriter that removes namespaces: http://stackoverflow.com/a/874344/578411 The solutions shown in that question don't work in your case because deep inside the the WriteXml method the XmlSerializer is called where it gets its default namespaces and AFAIK there is no code path that allows you to override those defaults. – rene Aug 30 '14 at 17:16
  • Thank you guys! I'd change my mind since there it seemed that there are no straightforward solution to my problem. I'm using extra tables with default types in my dataset instead. Cheers! – JustGreg Sep 08 '14 at 08:15

0 Answers0