1

VS2013 によって生成された私のオブジェクト '特別に貼り付け' 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)

Contacts オブジェクトを取得し、すべての deptcontact と deptcontact のすべての詳細を反復処理しようとしています。

4

0 に答える 0