KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
HI I have a xml document like this: <Students> <student name="A" class="1"/> <student name="B"class="2"/> <student name="c" class="3"/> </Students> I want to use XmlReader to read through this xml and return a list of students as List<student> . I know this can be achieved as follows: List<Student> students = new List<Student>(); XmlReader reader = XmlReader.Create("AppManifest.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "student") { students.Add(new Student() { Name = reader.GetAttribute("name"), Class = reader.GetAttribute("Class") }); } } I just want to know if there is any better solution for this? I am using silverlight 4. The xml structure is static, ie. it will have only one Students node and all the student node with above said attributes will only be there.
Tags (comma-separated)
Save Edits
Cancel