The tags 'school1', 'school2', 'grade1', 'grade2' are dynamically created. And number of
I want to read all
Since there are dynamic tags, I am able to read all
But I want to read them individually according to the grade.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Parul MaheshwariPosted Aug 22, 2017, 12:43 PM
Parul MaheshwariPosted Aug 22, 2017, 12:42 PM
string studentAge = "";
List
List
List
List
foreach (XmlNode node in doc.SelectNodes("root/academic"))
{
for (int i = 0; i < node.ChildNodes.Count-1; i++ )
{
schoolName = node.ChildNodes[i].LocalName;
foreach (XmlNode node1 in doc.SelectNodes("root/academic/" + schoolName))
{
for(int j = 0; j < node1.ChildNodes.Count; j++)
{
gradeName = node1.ChildNodes[j].LocalName;
foreach(XmlNode node2 in doc.SelectNodes("root/academic/"+schoolName+"/"+gradeName))
{
foreach (XmlNode node3 in node2.ChildNodes)
{
if (node3.LocalName.Equals("student"))
{
studentName = node3.SelectSingleNode("name").InnerText;
studentAge = node3.SelectSingleNode("age").InnerText;
schoolList.Add(schoolName);
gradeList.Add(gradeName);
nameList.Add(studentName);
ageList.Add(studentAge);
}
}
} // grade foreach ends
} // grade for ends
} // school foreach ends
} // school for ends
}
Midhun TpPosted Aug 18, 2017, 1:18 AM
Kailash PolaiPosted Aug 18, 2017, 1:10 AM