Further help required on classes

P

Peter Newman

Firstly a big thank you for the help pointing me in this direction, I have
managed to get this far ( section of code below) in reading a text file and
creating an XML file from it..

code
Do
Dim t As New Transaction
importLine = StripQuotes(sr.ReadLine)
If InStr(importLine, "TRAILER RECORD") Then Exit Do
' Set the values
t.LedgerRef = s.LedgerKey
t.Licence = s.License
s.Transactions.Add(t)
Loop Until InStr(importLine, "TRAILER RECORD") > 0

CLass

Imports System.Xml.Serialization
Imports System.IO

Public Class Transaction

Public _LedgerRef As String
<XmlAttribute("LedgerRef")> _
Public Property LedgerRef() As String
Get
Return _LedgerRef
End Get
Set(ByVal value As String)
_LedgerRef = value
End Set
End Property

Public _Licence As String
<XmlAttribute("Licence")> _
Public Property Licence() As String
Get
Return _Licence
End Get
Set(ByVal value As String)
_Licence = value
End Set
End Property

End Class

section ox XML result


<Transactions>
<Transaction LedgerRef="11111158908068131138" Licence="111111" >
<_LedgerRef>11111158908068131138</_LedgerRef>
<_Licence>111111</_Licence>
</Transaction>
<Transaction LedgerRef="22222258908068131138" Licence="222222" >
<_LedgerRef>22222258908068131138</_LedgerRef>
<_Licence>222222</_Licence>
</Transaction>
.. etc

what im trying to achieve is the following

<Transactions>
<Transaction LedgerRef="11111158908068131138" Licence="111111" />
<Transaction LedgerRef="22222258908068131138" Licence="222222" />

etc

any suggestions
 
C

Chris Dunaway

Firstly a big thank you for the help pointing me in this direction, I have
managed to get this far ( section of code below) in reading a text file and
creating an XML file from it..

code
Do
Dim t As New Transaction
importLine = StripQuotes(sr.ReadLine)
If InStr(importLine, "TRAILER RECORD") Then Exit Do
' Set the values
t.LedgerRef = s.LedgerKey
t.Licence = s.License
s.Transactions.Add(t)
Loop Until InStr(importLine, "TRAILER RECORD") > 0

CLass

Imports System.Xml.Serialization
Imports System.IO

Public Class Transaction

Public _LedgerRef As String
<XmlAttribute("LedgerRef")> _
Public Property LedgerRef() As String
Get
Return _LedgerRef
End Get
Set(ByVal value As String)
_LedgerRef = value
End Set
End Property

Public _Licence As String
<XmlAttribute("Licence")> _
Public Property Licence() As String
Get
Return _Licence
End Get
Set(ByVal value As String)
_Licence = value
End Set
End Property

End Class

section ox XML result

<Transactions>
<Transaction LedgerRef="11111158908068131138" Licence="111111" >
<_LedgerRef>11111158908068131138</_LedgerRef>
<_Licence>111111</_Licence>
</Transaction>
<Transaction LedgerRef="22222258908068131138" Licence="222222" >
<_LedgerRef>22222258908068131138</_LedgerRef>
<_Licence>222222</_Licence>
</Transaction>
.. etc

what im trying to achieve is the following

<Transactions>
<Transaction LedgerRef="11111158908068131138" Licence="111111" />
<Transaction LedgerRef="22222258908068131138" Licence="222222" />

etc

any suggestions

You didn't show the code where you actually create the XML so my guess
is the problem is there. What you have posted seems ok at first
glance.

Chris
 
C

Chris Dunaway

Firstly a big thank you for the help pointing me in this direction, I have
managed to get this far ( section of code below) in reading a text file and
creating an XML file from it..

code
Do
Dim t As New Transaction
importLine = StripQuotes(sr.ReadLine)
If InStr(importLine, "TRAILER RECORD") Then Exit Do
' Set the values
t.LedgerRef = s.LedgerKey
t.Licence = s.License
s.Transactions.Add(t)
Loop Until InStr(importLine, "TRAILER RECORD") > 0

CLass

Imports System.Xml.Serialization
Imports System.IO

Public Class Transaction

Public _LedgerRef As String
<XmlAttribute("LedgerRef")> _
Public Property LedgerRef() As String
Get
Return _LedgerRef
End Get
Set(ByVal value As String)
_LedgerRef = value
End Set
End Property

Public _Licence As String
<XmlAttribute("Licence")> _
Public Property Licence() As String
Get
Return _Licence
End Get
Set(ByVal value As String)
_Licence = value
End Set
End Property

End Class

section ox XML result

<Transactions>
<Transaction LedgerRef="11111158908068131138" Licence="111111" >
<_LedgerRef>11111158908068131138</_LedgerRef>
<_Licence>111111</_Licence>
</Transaction>
<Transaction LedgerRef="22222258908068131138" Licence="222222" >
<_LedgerRef>22222258908068131138</_LedgerRef>
<_Licence>222222</_Licence>
</Transaction>
.. etc

what im trying to achieve is the following

<Transactions>
<Transaction LedgerRef="11111158908068131138" Licence="111111" />
<Transaction LedgerRef="22222258908068131138" Licence="222222" />

etc

any suggestions

Now at second glance, I think I see your problem. Your property
backing fields should be private not public:

Public _Licence As String

should be

Private _Licence As String

And the same for _LedgerRef

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top