The BOOKING class listed is invalid: the serializer will be confused by a class which is a List of the same Type as one of its properties. Since there is one Message per Booking packet, you do not need a List at all.
I have no idea where partner, transaction or version
are supposed to show up. As is, I have them as Booking props because thats what your code shows. If there are supposed to be inside the block, then they are actually Message properties and Booking is empty.
Public Class BOOKING
Public Property partner As String
Public Property transaction As String
Public Property version As String
Public Property [Message] As BookingMessage
Public Sub New()
' create a new Msg object
[Message] = New BookingMessage
End Sub
' Message Properties
Public Class BookingMessage
Public Property MessageType As String
Public Property CustomerNumber As String
Public Property BookingReference As String
Public Property CustomerBookingReference As String
Public Property NoDrivers As String
End Class
End Class
Test code:
Dim B As New BOOKING
With B
.partner = "Foo"
.transaction = "ABC"
.Message.BookingReference = "123456"
.Message.CustomerBookingReference = "ziggy"
.Message.NoDrivers = "1"
End With
Dim x As New Xml.Serialization.XmlSerializer(GetType(BOOKING))
x.Serialize(New System.IO.FileStream("C:\Temp\Booking2.xml",
IO.FileMode.OpenOrCreate), B)
Output:
<?xml version="1.0"?>
<BOOKING xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<partner>Foo</partner>
<transaction>ABC</transaction>
<Message>
<BookingReference>123456</BookingReference>
<CustomerBookingReference>ziggy</CustomerBookingReference>
<NoDrivers>1</NoDrivers>
</Message>
</BOOKING>