public void ConvertDelimitedToXML(char delimiter, string file,string xmlFileName)
{
//create the objects we need
System.
Data.
DataSet xmlDataSet =
new System.
Data.
DataSet();
System.
Data.
DataTable xmlTable =
new System.
Data.
DataTable();
System.Data.DataRow xmlRows;
using (StreamReader reader =
new StreamReader
(file
))
{
//set the DataSetName of the DataSet
xmlDataSet.DataSetName = "YourName";
//set the NameSpace of the DataSet
xmlDataSet.Namespace = "YourNamespace";
//make sure we're at the beginning of the file
reader.BaseStream.Seek(0, SeekOrigin.Begin);
//add the header columns
foreach (string fields in reader.ReadLine().Split(delimiter))
{
//xmlDataSet.Tables(0).Columns.Add(fields);
xmlTable.Columns.Add(fields);
}
//now add the rows
while (reader.Peek() != -1)
{
xmlRows = xmlTable.NewRow();
foreach (string fields in reader.ReadLine().Split(delimiter))
{
xmlTable.Rows.Add(fields);
}
//add the new rows to the table
xmlTable.Rows.Add(xmlRows);
}
//add the table to the DataSet
xmlDataSet.Tables.Add(xmlTable);
//write out the XML
xmlDataSet.WriteXml(xmlFileName);
}
}