0

I have a similar case - I receive a DataSet object with data tables willed with data (e. g. customers table ...) from an external module (done by other programmer).

I then save the data set object to an xml using the writeXml method - here is my code

public void Save(string myXmlFilePath)
{        
    XmlWriterSettings settings = new XmlWriterSettings();
    settings.Encoding = System.Text.Encoding.UTF8; 
    settings.Indent = true;
    settings.NewLineHandling = NewLineHandling.None;

    using (XmlWriter writer = XmlWriter.Create(myXmlFilePath, settings))
    {
        ExportObject.WriteXml(writer);
        writer.Close();
    }
}

I get the standard xml file output structure like this:

<NewDataSet>
    <Customers>...</Customers>
    <Customers>...</Customers>
<NewDataSet>`

However I want the structure like this

<Customers>
    <Customer>...</Customer>
    <Customer>...</Customer>
</Customers>`

How can I achieve this?

maccettura
  • 10,514
  • 3
  • 28
  • 35
anar chipur
  • 109
  • 2
  • 10

2 Answers2

0

Specify the desired names to the dataset and the tables within it.

ExportObject.DataSetName = "Customers";
ExportObject.Tables[0].TableName = "Customer";
Alexander Petrov
  • 13,457
  • 2
  • 20
  • 49
0

A work around is to let WriteXml write however it likes and then do an XSD transform to the format you prefer.

LosManos
  • 7,195
  • 6
  • 56
  • 107