raulavi said:
Chris Shepherd said:
raulavi wrote:
vs2008 c#
how can I load an array from XML?
lets say I have now
string[] arr = {23,32,45,34,21,23,243,45 }
I want to read the values from XML.
What is the format of the XML document?
You could iterate over the elements however you choose, and then simply keep a
List<string>, Add the items to the list, and then use ToArray() on the list.
this is a simple sample of the XML.
<?wpl version="1.0"?>
<MyArr>
<MyNumbers>
<Number>1</Number>
<Number>2</Number>
<Number>3</Number>
</MyNumbers>
</MyArr>
this is some code we had to read XML but to a dataset (which I want to avoid )
DataSet1.ReadXml("..\form_Properties.xml")
Me.DataBindings.Add(New Binding("Number", DataSet1,
"Settings.Numbers"))
This can be done many ways.
A very traditional way is:
XmlDocument doc = new XmlDocument();
doc.Load(@"C:\numbers.xml");
List<int> lst = new List<int>();
foreach(XmlElement elm in doc.GetElementsByTagName("Number"))
{
lst.Add(int.Parse(elm.FirstChild.Value));
}
Arne