C# – Save a DataSet ds.WriteXml(…) without Tag


I can read and write a XML File into a Dataset with no problems, but if I save the DataSet with ds.WriteXml("Testdata.xml") a additional Tag <NewDataSet>.......</NewDataSet> is generrated.

Is it possible to supress this Tag genaration?

Best Solution

A dataset can contain multiple tables and a valid XML file must contain a single root node that's why it is wrapped in this node. You could specify the name of the root node when creating the DataSet:

var ds = new DataSet("root");

but if you want to remove it you could first load the DataSet into a XDocument or XmlDocument and then extract the node you need and save it into a file.