I'm calling a webservice, which returns XML with students. I need to store all students in my database (existing student table).
Right now I have this XMLStudentParser class that gets the XML, but I'm lost at how to proceed in storing each student record to the database. Do I use the XMLReader to loop through the students and add each student to a List<Student>
, and then save that list to the database?
Remote XML via webservice.
<Response>
<Result>True</Result>
<Table>
<Students>
<Student>
<StudentID>14165</StudentID>
<StudentName>Jeff Smith</StudentName>
<GroupId>9109</GroupId>
</Student>
<Student>
<StudentID>14168</StudentID>
<StudentName>Mary Jones</StudentName>
<GroupId>9109</GroupId>
</Student>
</Students>
</Table>
</Response>
My Student model
public class Student
{
public int StudentId { get; set; }
public string FullName { get; set; }
public int GrpId { get; set; }
}
How would the best practice code look to:
- Get the XML from the webservice
- Parse each student
- Store each student in the database