我想生成一个XML
序列化两个vb.net classes
我想写保姆联系信息和付款(付款是在列表,可以是现金,票,支票),如:
<roor>
<babysitters>
<babysitter>
<ID>1</ID>
<Name>Diana Swal</Name>
<Experience>3</Experience>
<PaymentInfo>
<bank>BBVA<bank>
<account>1234567898<account>
</PaymentInfo>
<Payment id=1 type="cash" date="2015-06-06">
<description>a descr </description>
</Payment>
<Payment id=2 type="cash" date="2015-07-16">
<description>a descr </description>
</Payment>
<Payment id=3 type="cash" date="2015-07-16">
<description>a descr </description>
</Payment>
</babysitter>
<babysitter>
<ID>2</ID>
<Name>Koryna Tokya</Name>
<Experience>1</Experience>
<PaymentInfo>
<bank>New York<bank>
<account>123477898<account>
</PaymentInfo>
<Payment id=11 type="check" date="2015-01-06">
<description>a descr </description>
</Payment>
<Payment id=22 type="check" date="2015-02-16">
<description>a descr </description>
</Payment>
<Payment id=33 type="cash" date="2015-03-16">
<description>a descr </description>
</Payment>
</babysitter>
</babysitters>
</roor>
这样做我正在尝试:
<XmlRoot ("roor")> _
Public Class roor
Public Property Babysitters As List(Of Babysitter)
Public Sub New()
Babysitters = New List(Of Babysitter)()
End Sub
End Class
<Serializable()>
Public Class Babysitter
Public Property ID As Integer
Public Property Name As String
Public Property Experience As Integer
'how to define payment info properties ?
' I guess an extra class is not necesary so instead of
'defining each one of payment info maybe one property or struct
'Public Property PaymentInfo As ????
Public Property PaymentInfo_bank As String
Public Property PaymentInfo_account As String
'for the payments I am using an array of payments
<XmlArrayItem("Payments")>
Public Property Payments As List(Of Payment)
Public Sub New()
Payments = New List(Of Payment)()
End Sub
End Class
<Serializable()>
Public Class Payment
<XmlAttribute("id")>
Public Property id As Integer
<XmlAttribute("type")>
Public Property type As String
<XmlAttribute("date")>
Public Property date As String
Public Property description As String
End Class
如何在xml中序列化信息?该代码定义是否会生成类似给定的xml?
答案 0 :(得分:2)
如果您有一个示例xml文件,那么您可以自动生成类以避免出现任何差异。