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...
--
-------------------------------------------------------
http://www.qnal.net/inkabletype
"Steve Bishop" <st****@viper.com> wrote in message news:eD**************@TK2MSFTNGP12.phx.gbl...
Could anyone give me an example of sending an array's variables to an
XML document all within a subroutine. I'm thinking of a basic example
capturing a form fields values into the array. Help appreciated.
Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!