Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27400

Serialization

$
0
0
Hi guys

I am trying to create a SAFT file
http://www.oecd.org/ctp/taxadministr...quirements.htm

I have the following class

Code:

Imports System.ComponentModel

<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class Header

    Private _companyAddress As List(Of CompanyAddress)

    Public Property AuditFileVersion As String
    Public Property CompanyID As String
    Public Property TaxRegistrationNumber As String

    Public Property CompanyAddress() As List(Of CompanyAddress)
        Get
            Return _companyAddress
        End Get
        Set(ByVal value As List(Of CompanyAddress))
            _companyAddress = value
        End Set
    End Property

    Public Sub New()
        _companyAddress = New List(Of CompanyAddress)
    End Sub

End Class

Public Class CompanyAddress

    Public Property AddressDetail As String
    Public Property City As String
    Public Property PostalCode As String
    Public Property Country As String

End Class

when i serialize the object i get

Code:

<Header>
  <AuditFileVersion>1.1.0</AuditFileVersion>
  <CompanyAddress>
    <CompanyAddress>
      <City>Porto</City>
      <PostalCode>4100</PostalCode>
    </CompanyAddress>
    <CompanyAddress>
      <City>Porto</City>
      <PostalCode>4100</PostalCode>
    </CompanyAddress>
    <CompanyAddress>
      <City>Porto</City>
      <PostalCode>4100</PostalCode>
    </CompanyAddress>
  </CompanyAddress>
</Header>

as you can see i get <CompanyAddress> element repeated...

The result i want to produce is something like this:

Code:


<Header>
  <AuditFileVersion>1.1.0</AuditFileVersion>
    <CompanyAddress>
      <City>Porto</City>
      <PostalCode>4100</PostalCode>
    </CompanyAddress>
    <CompanyAddress>
      <City>Porto</City>
      <PostalCode>4100</PostalCode>
    </CompanyAddress>
    <CompanyAddress>
      <City>Porto</City>
      <PostalCode>4100</PostalCode>
    </CompanyAddress>
</Header>

with only one element created for each item (CompanyAddress)

Any help ?

Viewing all articles
Browse latest Browse all 27400

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>