I\'m basically brand new to LINQ. I\'ve looked around a lot on here and am pretty confused. I\'ve seen some examples that allow me to strong type objects using LINQ but I do
I may be a little late to the party here, but I can't believe nobody has offered the XmlSerializer
option:
Public Class Product
Property Description As String
Property Price As Double
Public Shared Function FromXml(serverPath As String) As IEnumerable(Of Product)
Using fs = IO.File.OpenRead(serverPath)
Dim p As New Product
Return New XmlSerializer(p.GetType).Deserialize(fs)
End Using
End Function
End Class
You can then return an iEnumerable of Product from the shared function:
dim listOfProducts = Product.FromXml(Server.MapPath("~/App_Data/products.xml"))
This doesn't use LinqToXml
as such, but it deserializes the xml to an iEnumerable of product, which you can use Linq on as usual.