Reputation: 669
I have a peace of xml which I need to gather information off.
<response>
<students>
<student>
<educationalinstitutionname>Test One</educationalinstitutionname>
<academicqualificationtype>TestLevel One</academicqualificationtype>
<starttime>22/02/06</starttime>
<endtime>19/08/10</endtime>
<grade>A</grade>
</student>
<student>
<educationalinstitutionname>Test One</educationalinstitutionname>
<academicqualificationtype>TestLevel Two</academicqualificationtype>
<starttime>22/02/06</starttime>
<endtime>19/08/10</endtime>
<grade>B</grade>
</student>
<student>
<educationalinstitutionname>Test Two</educationalinstitutionname>
<academicqualificationtype>TestLevel Two</academicqualificationtype>
<starttime>22/02/06</starttime>
<endtime>19/08/10</endtime>
<grade>C</grade>
</student>
<student>
<educationalinstitutionname>Test Two</educationalinstitutionname>
<academicqualificationtype>TestLevel Three</academicqualificationtype>
<starttime>22/02/06</starttime>
<endtime>19/08/10</endtime>
<grade>D</grade>
</student>
</students>
The issue which I am having is that I need to parse the educationalinstitutionname once if it the same but gather the academicqualificationtype, starttime, endtime and grade for everything that it appears under the same educationalinstitutionname node.
XmlNodeList WordXMLNodeLists = XmlResponceDoc.SelectNodes("/response/students/student");
string GetDetaisl = string.Empty;
foreach (XmlNode GradeItem in WordXMLNodeLists)
{
string GetStartDate = EducationElement.SelectNodes("/response/students/student/starttime")[0].InnerText;
string GetEndDate = EducationElement.SelectNodes("/response/students/student/endtime")[0].InnerText;
string GetEstablishmentName = EducationElement.GetElementsByTagName("educationalinstitutionname")[0].InnerText;
string GetGrade = EducationElement.SelectNodes("/response/students/student/grade")[0].InnerText;
GetDetaisl = string.Concat(GetStartDate, " ", GetEndDate, " ", GetEstablishmentName);
if (GetDetaisl.Length == GetEstablishmentName.Length)
{
string GetGrades = GetGrade;
GetEducationNodeDate.Add(GetGrades);
}
else
{
GetEducationNodeDate.Add(GetDetaisl);
continue;
}
}
The issue which I am finding is that I cannot seem to loop through the name once and gather all the information in the document under that name for the establishment. Thanks for any help which you can provide
Upvotes: 0
Views: 39
Reputation: 89315
It isn't very clear what you're trying to achieve specifically. I assumed that basically you want value of most of nodes within <student>
tag :
XmlNodeList WordXMLNodeLists = XmlResponceDoc.SelectNodes("/response/students/student");
foreach (XmlNode GradeItem in WordXMLNodeLists)
{
string GetStartDate = GradeItem.SelectSingleNode("./starttime").InnerText;
string GetEndDate = GradeItem.SelectSingleNode("./endtime").InnerText;
string GetEstablishmentName = GradeItem.SelectSingleNode("./educationalinstitutionname").InnerText;
string GetGrade = GradeItem.SelectSingleNode("./grade").InnerText;
//do something with data gathered above
}
Upvotes: 1