Serializing a class

N

Nijazi Halimaji

Hi

I have written a class which is serializable. This works fine and the class
looks like this:


<Serializable()> Public Class Settings

Public Standard_DBVerknuepfung As String

Public Standard_NetDirNotfallPfad As String

Public Spezial_DBVerknuepfung As String

Public Spezial_NetDirNotfallPfad As String

End Class

When I serialize the class into a XML, then the XML-File looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Einstellungen xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Standard_DBVerknuepfung>W:\SBDATEN\ProgForm\SBStart.sbp</Standard_DBVerknuepfung>
<Standard_NetDirNotfallPfad>W:\SBDATEN</Standard_NetDirNotfallPfad>
<Spezial_DBVerknuepfung>C:\Restore\SBDATEN\PROGFORM\SBStart.sbp</Spezial_DBVerknuepfung>
<Spezial_NetDirNotfallPfad>C:\Restore\SBDATEN</Spezial_NetDirNotfallPfad>
</Einstellungen>


Now I modified the XML-File and added second values for "Einstellungen":

<?xml version="1.0" encoding="utf-8"?>
<Einstellungen xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Standard_DBVerknuepfung>W:\SBDATEN\ProgForm\SBStart.sbp</Standard_DBVerknuepfung>
<Standard_NetDirNotfallPfad>W:\SBDATEN</Standard_NetDirNotfallPfad>
<Spezial_DBVerknuepfung>C:\Restore\SBDATEN\PROGFORM\SBStart.sbp</Spezial_DBVerknuepfung>
<Spezial_NetDirNotfallPfad>C:\Restore\SBDATEN</Spezial_NetDirNotfallPfad>
</Einstellungen>
<Einstellungen>
<Standard_DBVerknuepfung>sdfasdf</Standard_DBVerknuepfung>
<Standard_NetDirNotfallPfad>sdfsdf</Standard_NetDirNotfallPfad>
<Spezial_DBVerknuepfung>sdfsdfsd</Spezial_DBVerknuepfung>
<Spezial_NetDirNotfallPfad>sdfsdfsd</Spezial_NetDirNotfallPfad>
</Einstellungen>

Now my question: What should I do deserialize all "Einstellungen" to my
class? I know that a array is needed, but how to do? If I let the
deserialize work trought, then I always get the values of the second
"Einstellungen"

Thanks for every help

Nijazi Halimaji
 
C

Charles Law

Hi Nijazi

What I generally do when I want to deserialise an xml file to an object
hierarchy in memory is do the reverse first. That is, I create the class
structure that I want in my programme, instantiate it, and then serialise it
to an xml file. That way, I create a file with exactly the right structure
for deserialisation.

If you create your array structure and serialise it, you will see exactly
how the file should be formed, and you are guaranteed to be able to
deserialise it.

HTH

Charles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top