I am a beginner programmer starting off with C#, and web services.
In the Service.cs
file of my web service, I create a ReadXMLFile()
method where I am trying to read an existing XML file, take the data from it and place it to the corresponding properties (DataMembers) that I created in the IService.cs
file.
My problem is that my code is basically not doing anything. I've tried looking for web sites and tutorials on this but there really isn't much out there, especially for a beginner like myself. Anyone have any idea how I should go about this, because what I've been trying so far is obviously wrong.
Below is my ReadXMLFile()
method.
void ReadXMLFile()
{
XmlTextReader reader = new XmlTextReader("ClassRoll.xml");
reader.Read();
while (reader.Read())
{
if (reader.Name == "id")
{
id = reader.ReadString();
}
else if (reader.Name == "firstname")
{
link = reader.ReadString();
}
else if (reader.Name == "lastname")
{
description = reader.ReadString();
}
else if (reader.Name == "count")
{
description = reader.ReadString();
}
else if (reader.Name == "testscore")
{
description = reader.ReadString();
}
}
}
this is an example of my xml file
<classroll>
<student>
<id>101010</id>
<lastname>Smith</lastname>
<firstname>Joe</firstname>
<testscores count="5">
<score>65</score>
<score>77</score>
<score>67</score>
<score>64</score>
<score>80</score>
</testscores>
</student>
</classroll>