loading array

R

raulavi

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.

thanks
 
C

Chris Shepherd

raulavi said:
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.

thanks

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.

Chris.
 
R

raulavi

I will detail the problem a little bit more

our code have many places were we set the array list, I would like to

use a dinamic approach to load/maintain these arrays...

whats the best way in XML to do it ?

we will need to update many customers daily with these arrays.
 
R

raulavi

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"))


I f I use the
Chris Shepherd said:
raulavi said:
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.

thanks

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.

Chris.
 
A

Arne Vajhøj

raulavi said:
Chris Shepherd said:
raulavi said:
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
 
R

raulavi

thank you Arne I will try it..
any good links to where I can read more about related items?

XML to trees?


Arne Vajhøj said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top