I have a xml file like this
<Document>
<Tests>
<Test>
<Name>A</Name>
<Type>Like A</Type>
<Members>
<Member>1</Member>
<Member>2</Member>
<Member>3</Member>
</Members>
</Test>
<Test>
<Name>B</Name>
<Type>Like B</Type>
<Members>
<Member>4</Member>
<Member>5</Member>
<Member>6</Member>
</Members>
</Test>
</Tests>
</Document>
Now I made a class to hold data for each Test nodes:
public class TestData
{
public string Name {get;set;}
public string Type {get;set;}
public List<string> Members = new List<string>();
public AddMembers(List<string> members)
{
Members.AddRange(members);
}
}
Now I am trying to use xpath to fill my TestData class, but I have problem adding members to the List I have. I am trying to use LINQ but I cant do it yet :(
public List<TestClass> GetTests()
{
List<TestClass> tests = new List<TestClass>();
TestClass test;
XPathNodeIterator it = nav.Select("/Document/Tests/Test");
foreach (XPathNavigator val in it)
{
test= new TestClass();
test.Name = val.SelectSingleNode(nav.Compile("Name")).Value;
test.Type = val.SelectSingleNode(nav.Compile("Type")).Value;
test.AddMembers(); //How can I return all the member nodes in a list?
tests.Add(test);
}
return tests ;
}