I just recently posted about trying to get an XMLTextReader to work, and I finally did. Unfortunately, now I cannot get it to take the data from the XML file because I am doing something wrong with my if statements. I need to have these if statements inside another if statement because they need the Student class to be created first. I have no idea how to approach this anymore. Below is my code, I am sure it is something stupid. I am not good a coding so I know its something I am missing.
while (reader.Read())
{
reader.MoveToContent();
if (reader.NodeType == XmlNodeType.Element && reader.Name == "student")
{
Student s = new Student();
if (reader.Name == "id")
{
s.ID = reader.ReadString();
}
if (reader.Name == "firstname")
{
s.FirstName = reader.ReadString();
}
if (reader.Name == "lastname")
{
s.LastName = reader.ReadString();
}
if (reader.Name == "score")
{
s.TestScores.Add(Convert.ToInt32(reader.ReadString()));
}
s.Average = 6.00;
Students.Add(s);
}
}
[EDIT] Even after I tell the XMLreader to move on to the next line with reader.MoveToCOntent(); it still skips all of the if statements.
I am begginers in programming, I would appreciate any new ideas and suggestions.