let the Framework do the work! Load your Array into a DataTable, the DataTable into a DataSet, and use WriteXML..guess I'm just lazy..
here is a quick and dirty:
private void ArrayToXML(object [] YourArray)
{
try
{
DataTable dt = new DataTable("SomeTable");
dt.Columns.Add("ArrayElements");
foreach (object o in YourArray)
{
DataRow dr = dt.NewRow();
dr["ArrayElements"] = o.ToString();
dt.Rows.Add(dr);
}
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.WriteXml("C:\\Somefile.xml"); //probably change this
}
catch (Exception ex)
{
//your handling
}
}
Some Inputs :
object [] myArray = {"Hello","this","should","work"};
ArrayToXML(myArray);
will give:
<?xml version="1.0" standalone="yes" ?>
- <NewDataSet>
- <SomeTable>
<ArrayElements>Hello</ArrayElements>
</SomeTable>
- <SomeTable>
<ArrayElements>this</ArrayElements>
</SomeTable>
- <SomeTable>
<ArrayElements>should</ArrayElements>
</SomeTable>
- <SomeTable>
<ArrayElements>work</ArrayElements>
</SomeTable>
</NewDataSet>
Of course you can tweak it as you like...