I've got some XML I'm trying to import with c#, which looks something like this:
<root>
<run>
<name = "bob"/>
<date = "1958"/>
</run>
<run>
<name = "alice"/>
<date = "1969"/>
</run>
</root>
I load my xml using
XElement xDoc=XElement.Load(filename);
What I want to do is have a class for "run", under which I can store names and dates:
public class RunDetails
{
public RunDetails(XElement xDoc, XNamespace xmlns)
{
var query = from c in xDoc.Descendants(xmlns + "run").Descendants(xmlns + "name") select c;
int i=0;
foreach (XElement a in query)
{
this.name= new NameStr(a, xmlns); // a class for names
Name.Add(this.name); //Name is a List<NameStr>
i++;
}
// Here, i=2, but what I want is a new instance of the RunDetails class for each <run>
}
}
How can I set up my code to create a new instance of the RunDetails class for every < run>, and to only select the < name> and < date> inside a given < run>?