Набор данных из одной таблицы в 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);
}
Если в наборе данных более одной таблицы, скажем, это отношение master-detail, тогда метод будет точно таким же.Просто убедитесь, что вы создали DataRelation между таблицами и задали для свойства Relationship Nested
значение true, как показано в следующем коде
//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;
Надеюсь, это поможет