Enumerate over the array to build an XElement
Imports System.Collections.Generic
Class Car
Public PetName As String
Public ID As Integer
End Class
Module Program
Sub Main()
Dim data As New List(Of Car)
data.Add(New Car With {.PetName = "A", .ID = 10})
data.Add(New Car With {.PetName = "Pat", .ID = 11})
data.Add(New Car With {.PetName = "Danny", .ID = 12})
data.Add(New Car With {.PetName = "B", .ID = 13})
Dim vehicles As XElement = _
New XElement("Inventory", _
From c In data _
Select New XElement("Car", _
New XAttribute("ID", c.ID), _
New XElement("PetName", c.PetName) _
) _
)
Console.WriteLine(vehicles)
End Sub
End Module
Related examples in the same category