Sunday, September 21, 2008

LINQ to XML

Simple Query Sample


Module Module1

Sub Main()
Dim doc = XDocument.Load("c:\books.xml").Elements
Dim query = From data In doc.Elements _
Where data.Element("title") = "Python"
For Each g In query
Console.WriteLine(g.Element("author").Value)
Next
Console.ReadLine()
End Sub

End Module

Sample File

<books>
<book><title>Python</title><author>Guido</author></book>
<book><title>Haskell</title><author>Books</author></book>
</books>

No comments:

Post a Comment