Reputation: 581
I know how to serialize an xml. But this following example I have never done yet. And I can't figure out how to do it either.
<Products>
<row **id="10"**>
<ProductName>Cola</ProductName>
<Amount>3</Amount>
</row>
<row **id="20"**>
<ProductName>Fanta</ProductName>
<Amount>6</Amount>
</row>
</Products>
So I want use xml serialization, most of the xml is done, but this little part of it remains.
I can't manage to put the id behind the row. I bet I need to use xmlattribute but I don't really know how to implement.
Can someone please help me out on how to get the id in "Row" element with xml serialization specifically.
(I did find some way to do it with another way, but since this XML is pretty large and most of it I finished so I would love to continue. And also don't want to go around any little problem.)
Upvotes: 1
Views: 91
Reputation: 43743
You just need to create an ID member in your class and then mark it with the XmlAttribute
attribute, for instance:
Public Class MyRow
<XmlAttribute()> _
Public Property id() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property
Private _id As Integer
Public Property ProductName() As String
Get
Return _productName
End Get
Set(ByVal value As String)
_productName = value
End Set
End Property
Private _productName As String
Public Property Amount() As Integer
Get
Return _amount
End Get
Set(ByVal value As Integer)
_amount = value
End Set
End Property
Private _amount As Integer
End Class
Upvotes: 2