Nested XML Serialization - List Issue

vegaloz

New member
Joined
Jul 22, 2008
Messages
2
Programming Experience
Beginner
I made the following serial nested xml, using as an example Serializing Nested XML - CodeProject

VB.NET:
Imports System.Xml.Serialization
Imports System.Xml

<Serializable()> _
Public Class clsTranReq

	Private TranTypeString As String
	<Xml.Serialization.XmlElement("TranType")> _
	Public Property TranType() As String
		Get
		  TranType = TranTypeString
		End Get
		Set(ByVal Value As String)
		  TranTypeString = Value
		End Set
	End Property
	
	Private PanString As String
	<Xml.Serialization.XmlElement("PAN")> _
	Public Property PAN() As String
		Get
		  PAN = PanString
		End Get
		Set(ByVal Value As String)
		  PanString = Value
		End Set
	End Property
	
	<Xml.Serialization.XmlElement("ProcCode")> _
    Public ProcCode As List(Of ProcCode)
	
	Public Sub New()
        ProcCode = New List(Of ProcCode)
    End Sub

End Class
VB.NET:
Public Class ProcCode
    Private _type As String 
    Private _value As String 
	
	<System.Xml.Serialization.XmlAttributeAttribute()> _
    Public Property type() As String
        Get
            Return _type
        End Get
        Set(ByVal value As String)
            _type = value
        End Set
    End Property

	<System.Xml.Serialization.XmlTextAttribute()> _
    Public Property value() As String
        Get
            Return _value
        End Get
        Set(ByVal value As String)
            _value = value
        End Set
    End Property
    
End Class

The situation on how to invoke the List - ProcCode in Visual Basic Commands.

VB.NET:
Dim p As New clsTranReq
p.TranType = "Authorization"
p.PAN = "12345"
p.ProcCode. [COLOR="red"]<---- What should be the commans to set the value and type.[/COLOR]

Your help will be greatly appreciated.
 
Last edited by a moderator:
ProcCode property is type List(Of ProcCode), so you create a new instance of ProcCode and use the Add method to add it to the list. Add method was the first option that was presented to you when you typed "p.ProcCode."

Some thoughts, why did you add the Serializable attribute to class clsTranReq (bad name btw), it has nothing to do with xml serialization. Also, why did you import System.Xml.Serialization namespace and still qualify all uses, for example "Xml.Serialization.XmlElement" instead of the simple "XmlElement"? And later in ProcCode class you use "XmlAttributeAttribute", the last 'Attribute' part can be left out, like the other ones where you use XmlElement instead of XmlElementAttribute. Yes, I know, you just copied from the article :(

I added code tags to the codes in your post, something you should do yourself next time. The forum posting editors here are easy to use.
 
Back
Top