我的对象由 VS2013 'paste as special' fn 生成
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True), _
System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=False)> _
Partial Public Class Contacts
Private deptContactField As ContactsDeptContact
'''<remarks/>
Public Property DeptContact() As ContactsDeptContact
Get
Return Me.deptContactField
End Get
Set(value As ContactsDeptContact)
Me.deptContactField = Value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
Partial Public Class ContactsDeptContact
Private contactIdField As UInteger
Private descriptionField As String
Private personField As ContactsDeptContactPerson
'''<remarks/>
Public Property ContactId() As UInteger
Get
Return Me.contactIdField
End Get
Set(value As UInteger)
Me.contactIdField = Value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute([Namespace]:="http://schemas.sommething.org/Company.Model")> _
Public Property Description() As String
Get
Return Me.descriptionField
End Get
Set(value As String)
Me.descriptionField = Value
End Set
End Property
'''<remarks/>
Public Property Person() As ContactsDeptContactPerson
Get
Return Me.personField
End Get
Set(value As ContactsDeptContactPerson)
Me.personField = Value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
Partial Public Class ContactsDeptContactPerson
Private dateOfBirthField As Object
Private firstNameField As String
Private lastNameField As String
Private addressesField As ContactsDeptContactPersonAddresses
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute([Namespace]:="http://schemas.sommething.org/Company.Model")> _
Public Property DateOfBirth() As Object
Get
Return Me.dateOfBirthField
End Get
Set(value As Object)
Me.dateOfBirthField = Value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute([Namespace]:="http://schemas.sommething.org/Company.Model")> _
Public Property FirstName() As String
Get
Return Me.firstNameField
End Get
Set(value As String)
Me.firstNameField = Value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute([Namespace]:="http://schemas.sommething.org/Company.Model")> _
Public Property LastName() As String
Get
Return Me.lastNameField
End Get
Set(value As String)
Me.lastNameField = Value
End Set
End Property
'''<remarks/>
Public Property Addresses() As ContactsDeptContactPersonAddresses
Get
Return Me.addressesField
End Get
Set(value As ContactsDeptContactPersonAddresses)
Me.addressesField = Value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
Partial Public Class ContactsDeptContactPersonAddresses
Private personAddressField As PersonAddress
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute([Namespace]:="http://schemas.sommething.org/Company.Model")> _
Public Property PersonAddress() As PersonAddress
Get
Return Me.personAddressField
End Get
Set(value As PersonAddress)
Me.personAddressField = Value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="http://schemas.sommething.org/Company.Model"), _
System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://schemas.sommething.org/Company.Model", IsNullable:=False)> _
Partial Public Class PersonAddress
Private addressLine1Field As String
'''<remarks/>
Public Property AddressLine1() As String
Get
Return Me.addressLine1Field
End Get
Set(value As String)
Me.addressLine1Field = Value
End Set
End Property
End Class
反序列化后,我得到一个异常
Message="There is an error in XML document (1, 237)."
InnerException {"Input string was not in a correct format."}
我试着把XMLAttribute([ElementName]:
,这导致了同样的例外。
Dim p As New Contacts
Dim x As New XmlSerializer(p.GetType)
Dim p2 As New Contacts()
p2 = CType(x.Deserialize(objStreamReader), Contacts)
尝试获取联系人对象并遍历所有部门联系人和部门联系人的所有详细信息。