I have a problem where I am trying to get the values of my nested elements in my XML file.
-<Modules>
-<Modules4>
-<Module>
<Name>dasd</Name>
<Code>dasdasdas</Code>
<Credits>40</Credits>
</Module>
-<Module>
<Name>dasdasd</Name>
<Code>dasdasd</Code>
<Credits>40</Credits>
</Module>
</Modules4>
<Modules5/>
<Modules6/>
</Modules>
This is the XML file, i am trying to create a condition where if the reader finds the "Modules4" Element, then get the nested elements "Name", "Code" and "Credits" if this question has been answered, please direct me to it as I can not find it anywhere.
using (XmlReader reader = XmlReader.Create("SavedData.xml"))
while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.Name == "Modules4"){
switch (reader.Name)
{
case "Name":
string name = reader.ReadString();
Console.WriteLine(name);
break;
case "Code":
string Code = reader.ReadString();
Console.WriteLine(Code);
break;
case "Credits":
break;
}
}
}
}
}
This is my code.
Thanks.