Из таблицы данных это будет примерно так
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("last", typeof(string));
dt.Columns.Add("phone", typeof(string));
dt.Columns.Add("adresse", typeof(string));
dt.Columns.Add("citie", typeof(string));
dt.Columns.Add("age", typeof(string));
dt.Columns.Add("mp", typeof(string));
dt.Columns.Add("dpa", typeof(string));
dt.Columns.Add("New A", typeof(string));
dt.Columns.Add("New B", typeof(string));
dt.Columns.Add("New C", typeof(string));
dt.Columns.Add("New D", typeof(string));
for (xlRow = 2; xlRow <= xlRange.Rows.Count; xlRow++)
{
if (xlRange.Cells[xlRow, 2].Text != "")
{
dt.Rows.Add(new object[] {
xlRange.Cells[xlRow, 1].Text,
xlRange.Cells[xlRow,2].Text,
xlRange.Cells[xlRow, 3].Text, xlRange.Cells[xlRow, 4].Text,
xlRange.Cells[xlRow, 5].Text, xlRange.Cells[xlRow, 6].Text,
xlRange.Cells[xlRow, 7].Text, xlRange.Cells[xlRow, 8].Text,
xlRange.Cells[xlRow, 9].Text, xlRange.Cells[xlRow, 10].Text,
xlRange.Cells[xlRow, 11].Text, xlRange.Cells[xlRow, 12].Text,
xlRange.Cells[xlRow, 13].Text
});
}
}
dataGridView1.DataSource = dt;
string header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Sheet1></Sheet1>";
XDocument doc = XDocument.Parse(header);
XElement sheet1 = doc.Root;
foreach (DataRow row in dt.AsEnumerable())
{
XElement rd = new XElement("rd", new object[] {
new XElement("id", row["id"]),
new XElement("name", row["name"]),
new XElement("last", row["last"]),
new XElement("phone", row["phone"]),
new XElement("refF", new object[] {
new XElement("adresse", row["adresse"]),
new XElement("citie", row["citie"]),
}),
new XElement("age", row["age"]),
new XElement("mp", new XElement("degree", row["mp"])),
new XElement("dpa", row["dpa"])
});
sheet1.Add(rd);
}
doc.Save(FILENAME);
}
}
}