Many times we need to manage the projects that just process specific information. Like if we consider a project that handles information about student(name,rno,course,class). So each student will have this information. To very easy way, if we create an XML file with one of the student. Creating a xml with this info is not very tough job.
Upto this point, half is done. Now we just need to get a class which can carry this information for various purposes and which can be written directly to xml file and also can read data from xml file( easiest way is serialize/deserialize mechanism can be very useful)
Now to get exact class that can be serialized directly to xml can be easily obtained from xsd utility of Visual Studio. just open the Visual Studio Command Prompt, and get the xsd file for your xml file and then convert this file directly to required class file. So the steps that can be needed to get the class are as below:
1. Create xml file say 'MyXml.xml'
2. run xsd MyXml.xml, will result MyXml.xsd
3. run xsd MyXml.xsd /c /l:vb, will result MyXml.vb
[the class can be constructed in various ways by using xsd, for details refer xsd documentation.]
note, in step 2 and 3, if current directory for running the command is same that is containing the MyXml.xml file then use command as such, else specify the full path of the file(s). Also target for the resulting file also can be specified(refer xsd documentation).
now we are with a class for which an object can be easily serialized/deserialized. So create collection of objects to carry all the records, applly any type of manipulations and serialize with XMLSerializer to write it to xml directly without worring about most of the validations as most are handled by serializers.
No comments:
Post a Comment