[dba-VB] XML and class serialization

jwcolby jwcolby at colbyconsulting.com
Sat Sep 19 21:05:41 CDT 2009


In another look at the uses of XML, many moons ago when I was trying to learn VB.Net, I wrote some 
stuff which used classes to store data.  I am going to generalize here since I only vaguely remember 
what I did.  Please pardon me if I use terms wrongly, and jump right in with the correct terminology.

IIRC...

A class can inherit the serializer interface which allows the controlling class to call a method of 
the data class and tell it to "serialize" itself to an XML file or to load itself from an XML file 
(actually a stream IIRC).  This was really quite cool stuff in a way since you could enter data into 
a form, store the data into a class instance, enter more data into a form, store that in another 
class instance, storing all of these instances in a collection.  Then you could write the whole 
thing out to a stream which ended up being an xml file on disk.  Load the whole thing back out of 
the file on disk into the data class instances and store them in the collection.

Obviously you could likewise load classes from data in a table or anywhere else you might get source 
data.

This ended up being a quick and dirty and EASY to implement (once you learned how to do it of 
course) way of storing and loading data.  No database file required, just XML files on disk.  Now I 
do not want to get back into the efficiency thing, I freely admit that XML has a HUGE overhead.

I am taking a course in c#.  One assignment is to create a "grading program" where a form is used to 
enter grades.  Three types of grades, each with a different weight.  Enter a bunch of grades and 
calculate a final grade.

To make it interesting and learn how to use classes and collections in C# I am taking the grades and 
storing them in class instances, storing the instances in a collection.  This allows me to move back 
and forth in the entered grades, make corrections if there is a data entry error etc.  A bit beyond 
the scope of the assignment but more interesting.

So... if I make the classes serializable, I can then store them out to an XML file and read them 
back again.

It seems the instructor knows barely more than I do about C# so it should float her boat.

-- 
John W. Colby
www.ColbyConsulting.com



More information about the dba-VB mailing list