This is an example of what my XML file typically looks like. It can contain any amount of assignments and any amount of modules and can contain 3 levels. (I haven't included the other 2 levels for now).
<course name="engineering">
<level4>
<module name="electric" credit="22">
<assignment name="wer" marks="22" weight="50">
</assignment>
<assignment name="asd" marks="50" weight="50">
</assignment>
</module>
</level4>
</course>
This is what I have so far
while (tr.Read())
{
tr.MoveToElement();
if (tr.Name == "Course") {
courseXML.Name = tr.GetAttribute("name");
}
if (tr.Name == "Level4") {
}
}
I am reading the XML file but I stumbled upon a problem. How do I get to module elements and the assignment elements and how would I be able to iterate through them because my XML file can contain any amount of modules and assignment.
XDocumentorXElementclasses. You can simply use linq to find nodes. For example you may find this post helpful: How to properly search xml document using LINQ C#.