I tried several different approaches and cannot seem to deserialize an XML into a list of classes. This is what my XML looks like:
<?xml version="1.0" encoding="utf-8"?>
<EmployeeDataList>
<EmployeeData>
<IsActive>true</IsActive>
<Id>123456</Id>
<FullName>JOHN SMITH</FullName>
</EmployeeData>
<EmployeeData>
<IsActive>true</IsActive>
<Id>998822</Id>
<FullName>BILL SMITH</FullName>
</EmployeeData>
</EmployeeDataList>
I always get the first node of employee lists so my .NET code looks like:
Dim empDatas = xdoc.Elements("EmployeeDataList")
Dim xempDataList As XElement = empDatas(0)
Dim serXml As New XmlSerializer(GetType(List(Of EmployeeData)))
Dim empDataList As List(Of EmployeeData) = CType(serXml.Deserialize(xempDataList.CreateReader), List(Of EmployeeData))
Debug.Print("EmployeeDatas count={0}", empDataList.Count)
and my class looks like:
<Serializable>
Public Class EmployeeData
Public IsActive As Boolean
Public Id As String
Public FullName As String
End Class
The result of this is an exception
System.InvalidOperationException: There is an error in XML document (0, 0). ---> System.InvalidOperationException: <EmployeeDataList xmlns=''> was not expected.
Just not sure where I am going wrong.