Monday, March 22, 2010

XML Serialize with multiple classes inherited in a class to serialize

_
_
Public Class REPORT_CONFIG

Public Property EXCHANGE() As Object
Get
EXCHANGE = mvarEXCHANGE
End Get
Set(ByVal Value As Object)
mvarEXCHANGE = Value
End Set
End Property
Public Property STATUS() As Object
Get
STATUS = mvarSTATUS
End Get
Set(ByVal Value As Object)
mvarSTATUS = Value
End Set
End Property
end class

here exchange is one class and status is another class.These two classes available in report_Config class as objects,so we have to use xml include

XML SERIALIZATION

Try


Dim oSerialiser As New XmlSerializer(GetType(REPORT_CONFIG))
Dim oStream As Stream = New FileStream("C:\REPORT_CFG_OBJ12.xml", FileMode.Create)
oSerialiser.Serialize(oStream, m_uiREPORT_CONFIG)

oStream.Close()



Catch caught As Exception
MessageBox.Show(caught.Source)
End Try


DESERIALIZATION:

Dim fs As New FileStream("C:\REPORT_CFG_OBJ12.xml", FileMode.Open)
Dim newXs As New XmlSerializer(GetType(CEMDAS.REPORT_CONFIG))
Dim OBJ_REPORT_CFG As CEMDAS.REPORT_CONFIG = DirectCast(newXs.Deserialize(fs), CEMDAS.REPORT_CONFIG)
fs.Close()

No comments:

Post a Comment