I have a BOOKING class that inherits a list (of Message) I was wondering how to serialize this. my BOOKING class contains the property of Message and 3 attributes called partner, transaction and version,
My Message class has numerous properties to create a booking,
now when I want to serialize I use this
Dim z As New BOOKING
Dim x As New Message
z.partner = "company name"
z.transaction = "BOOKING"
z.version = "1.0"
x.MessageType = "C"
x.CustomerNumber = "123"
x.BookingReference = "5845"
x.CustomerBookingReference = "036598"
x.OutwardRoute = "PEMROS"
x.SailingDate = "20120107"
z.Message = x
SaveAsXML(z)
with the save as xmlfunction code below
Public Shared Function SaveAsXML(ByRef val As BOOKING)
Try
Dim objStreamWriter As New StreamWriter("c:\ftptest\New Booking\" + val.FileName)
Dim y As New XmlSerializer(val.GetType)
y.Serialize(objStreamWriter, val)
objStreamWriter.Close()
Return True
Catch ex As Exception
Throw ex
End Try
End Function
any idea where I'm going wrong?
my BOOKING class is as follows
Public Class BOOKING : Inherits List(Of Message)
Private Property MessageProperty As Message
<XmlAttribute>
Public Property partner As String
<XmlAttribute>
Public Property transaction As String
<XmlAttribute>
Public Property version As String
Public Property Message As Message
Get
Return MessageProperty
End Get
Set(value As Message)
MessageProperty = value
End Set
End Property
Also here is the xml created by the above code.
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
Here is my deserializing code
Try
Dim Samples As BOOKING
Using objStreamReader As New StreamReader(filepath) 'Path where file is
Dim x As New XmlSerializer(GetType(BOOKING), New XmlRootAttribute("BOOKING"))
Samples = x.Deserialize(objStreamReader)
End Using
Form1.DataGridView1.DataSource = Samples
Return True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try