It is basically just the reverse of the code to serialize, but first you should make a change to the serializing part in SaveAsXML:
Using fs As New System.IO.FileStream("C:\ftptest\New Booking\4854.xml",
IO.FileMode.OpenOrCreate)
Dim x As New Xml.Serialization.XmlSerializer(GetType(BOOKING))
x.Serialize(fs, val)
End Using
Generally, if something implementes a Dispose Property, use it and the easiest way is with a Using
block. To deserialize:
Dim Bb As BOOKING
Using fs As New System.IO.FileStream(myFileName, IO.FileMode.Open)
Dim y As New Xml.Serialization.XmlSerializer(GetType(BOOKING))
Bb = CType(y.Deserialize(fs), BOOKING)
End Using
If you are using Option Strict (and you really should be), Ctype
just converts the return from the serializer from Object to Booking.
Finally, BookingMessage
properties could be auto implement properties like those in Booking
. No real need for all that code in this case.