Deserialize XML with multiple table to List

  • Thread starter Thread starter Shanssv
  • Start date Start date
S

Shanssv

Guest
I have a following XML (company was added) but the original xml was only with Quote table.

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfQuote xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="XML Schema">

<Quote>
<QuoteText>Hello World</QuoteText>
<Author>Unknown</Author>
<Category>Some Category</Category>
<QuoteDate>0001-01-01T00:00:00</QuoteDate>
</Quote>

<Quote>
<QuoteText>Foo Bar</QuoteText>
<Author>Somebody Else</Author>
<Category>Some Other Category</Category>
<QuoteDate>9999-12-31T23:59:59.9999999</QuoteDate>
</Quote>

<Company>
<Name>Name1</Name>
<City>Unknown</City>
<Zip>34354</Zip>
</Company>

<Company>
<Name>Name2</Name>
<City>Unknown</City>
<Zip>5656</Zip>
</Company>

</ArrayOfQuote>

And i have following codes in vb.net

Public _Quote As List(Of Quote)
Public _Company As List(Of Company)

Sub Deserialize(filePath As String) As List(Of Quote)

Using sr As New StreamReader(filePath)
Dim serializer As New XmlSerializer(GetType(List(Of Quote)))
_Quote = CType(serializer.Deserialize(sr), List(Of Quote))
End Using

End Sub

<Serializable()>
Public Class Quote
Public Property QuoteText As String
Public Property Author As String
Public Property Category As String
Public Property QuoteDate As DateTime
End Class

<Serializable()>
Public Class Company
Public Property Name As String
Public Property City As String
Public Property Zip As Integer
End Class

Above sub converts my XML to List(Of Quote) but i want to modify the sub so that it also generates List(Of Company) as well as other tables. I will have separate XMLs in one directory and want to generate list for each table in XML. Any help? thanks.

Continue reading...
 
Back
Top