Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: XML : Serialize / Deserialize (SOLVED)  (Read 268 times)
newborn
Customers
Community Member
*****
Posts: 2422


WWW
« on: May 31, 2008, 11:48:08 PM »

Okay, so I got my things working to serialize all my map (landscape, lights, models, you name it).

I'm using this to serialize a class, which basically takes everything that is public from the class and dumps it in a XML file:
Code:
    Private Sub Compile_Materials()

        ' Serialize       
        Dim filePath = pathCompiled & "maps\" & mapName & "\xml\materials.xml"
        Dim stream As New System.IO.StreamWriter(filePath)
        Dim inst As New XmlSerializer(CoreMaterial.GetType)
        inst.Serialize(stream, CoreMaterial)
        stream.Close()

    End Sub


My problem is when I try to deserialize the map. It does a marvelous job at reading the file and dumping the XML file into an instance, but wouldn't be much simpler if the deserialization would feed the variables and lists of the class instead?

Code:
    Private Sub Decompile_Materials()

        ' Deserialize
        Dim filePath = pathCompiled & "maps\" & mapName & "\xml\materials.xml"
        Dim stream As New System.IO.StreamReader(filePath)
        Dim xml As New XmlSerializer(CoreMaterial.GetType)
        Dim inst As New MaterialManager()
        inst = xml.Deserialize(stream)
        stream.Close()

        ' Rebuild
        CoreMaterial.Rebuild(inst)

    End Sub

I must be missing something here because it makes no sense to me that all the info be dumped in an instance and not automagically feed the variables of the CoreMaterial class. The only I found to work around this is to pass the instance to the class and rebuild the whole thing from the parameters, which is a serious pain in the butt.
« Last Edit: May 31, 2008, 11:52:10 PM by newborn » Logged

newborn
Customers
Community Member
*****
Posts: 2422


WWW
« Reply #1 on: May 31, 2008, 11:51:57 PM »

Gosh, now I feel embarrassed! It is 1am but gee, how could I have missed that?

Code:
   Private Sub Decompile_Materials()

        ' Deserialize
        Dim filePath = pathCompiled & "maps\" & mapName & "\xml\materials.xml"
        Dim stream As New System.IO.StreamReader(filePath)
        Dim xml As New XmlSerializer(CoreMaterial.GetType)
        Dim inst As New MaterialManager()
        inst = xml.Deserialize(stream)
        stream.Close()

        ' Pass info
        CoreMaterial = inst

        ' Rebuild
        CoreMaterial.Rebuild(inst)

    End Sub

Anywho, case closed.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks