Pauly Man Posted September 22, 2004 Posted September 22, 2004 Hi guys, I am having REAL difficulty getting something to work. I have a simple class and associated collection class. The class has a few properties, and the collection class houses instances of the classes. The class looks basically like this i pseudo code Class Student() Name as String Age as Integer Address as String End Class The collection class is just a list of the students. I can easily serialize the collection class s_c, which we can assume I've already filled with students: imports system.io imports system.xml.serialization dim serializer as new xmlserializer(gettype(student)) dim sw as new streamwriter("data.xml") dim s as new student for each s in s_c serializer.serialize(sw,s) next s This creates an xml document, as I require. But how do I get that xml data back from the xml file into my student collection via the student class? What I mean is, I want to read each students data back into an instance of the student class, and add it to the student collection. The reverse of the above process. Quote
Administrators PlausiblyDamp Posted September 22, 2004 Administrators Posted September 22, 2004 (edited) Something like the following should do it Dim sr As New StreamReader("data.xml") Do s = serializer.Deserialize(sr) If s Is Not Nothing Then sc.Add(s) End If Loop Until s Is Nothing Edited September 22, 2004 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.