A dataset of a single table to XML
private void SingleTableToXml()
{
DataSet myDS = getDataSet();
// To write out the contents of the DataSet as XML,
// use a file name to call the WriteXml method of the DataSet class
myDS.WriteXml(Server.MapPath("filename.xml"), XmlWriteMode.IgnoreSchema);
}
if you have more than one table in the dataset, say it a master-detail relationship, then the method is exactly the same. Just make sure to create the DataRelation between tables and set the relation Nested
property to true as in the following code
//Get the primary key column from the master table
DataColumn primarykey = myDS.Tables["Categories"].Columns["CategoryID"];
//Get the foreign key column from the detail table
DataColumn foreignkey = myDS.Tables["Products"].Columns["CategoryID"];
//Assign a relation
DataRelation relation = myDS.Relations.Add(primarykey, foreignkey);
//Ask ADO.NET to generate nested XML nodes
relation.Nested = true;
Hope it helps