|
-
July 19th, 2011, 01:03 PM
#1
[RESOLVED] populate list/array from specific XML nodes
I wonder if anyone can help me with this problem. What I'm trying to do is populate a string list with values based on the name from the XML file. In other words
list list = new list
for each row in XML file with var name "cabin",
list.add -> cabin.value
I then want to convert this list to and int array so I can perform numeric operations etc.
At the moment the code I have is not populating the list atal I have tested with labels etc here it is.
_______________________________________________________________
//Load XML document
XmlDocument xml = new XmlDocument();
xml.LoadXml(Server.MapPath("~/Upload/" + FileUpload1.FileName));
// xnList = nodes -> rows with Cabin
XmlNodeList xnList = xml.SelectNodes("/root/row[@name=' Cabin']");
//create a string list
List<string> strvalues = new List<string>();
//populate list with values @ node Cabin
foreach (XmlNode xn in xnList)
{
strvalues.Add(xn["value"].InnerText); //**This line of code is trying to populate the list
}
//convert string array to int array for data manipulation
int[] values = strvalues.Select(x => int.Parse(x)).ToArray();
for (int i = 0; i < values.Length; i++)
{
//print array
Debug.WriteLine(values[i]);
}
}
_________________________________________________________________________
and here is a sample of the XML file
_________________________________________________________________________
<root>
<row>
<var name="Name" value="Rusell" />
<var name=" Surname" value=" Anthony" />
<var name=" Country" value=" UK" />
<var name=" Job" value="Web Designer" />
<var name=" Cabin" value="345" />
</row>
<row>
<var name="Name" value="Wolf" />
<var name=" Surname" value=" Werner" />
<var name=" Country" value=" Germany" />
<var name=" Job" value="Linux IT" />
<var name=" Cabin" value="234" />
</row>
</root>
________________________________________________________________________
If anyone can give me a hand here Id appreciate it.
Just to be clear,
- the user will select a value, such as cabin from a dropdownlist.
- I then need to put all values of Cabin into a list/array so I can use it in a method that takes an array of values as the parameter
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|