I'm trying to read a XML in C#, using a button in WPF. I have this XML file:
<?xml version="1.0" encoding="utf-8" ?>
<date>
<Disciplina nume="Disc1" cadru="Cadru1">
<Student>
<Nume>Student1</Nume>
<Nota>9</Nota>
</Student>
</Disciplina>
</date>
In the reading Button i have this code:
XmlTextReader rd = new XmlTextReader(@"Test.xml");
string dnume = "", dcadru = "", snume = "",snota="", element = "";
while ( rd.Read() )
{
switch (rd.NodeType)
{
case XmlNodeType.Element:
element = rd.Name;
break;
case XmlNodeType.Text:
if (element == "Disciplina")
{
dnume = rd.GetAttribute("nume");
dcadru = rd.GetAttribute("cadru");
}
else
if (element == "Student")
{
}
break;
case XmlNodeType.EndElement:
if (rd.Name == "Student1")
{
MessageBox.Show("");
}
break;
}
}
rd.Close();
The problem is that I don't know how to read the information from the Student node. Can you help me?
XmlTextReader? It's considerably simpler to just load anXDocument...