O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Querying XML Documents with LINQ to XML

LINQ to XML also provides query support for XML structures. Here’s another example:

Dim fleet = <?xml version="1.0"?>
               <fleet>
                   <vehicle>
                       <licensePlate>MS-VB 2010</licensePlate>
                       <manufacturer>Mack</manufacturer>
                       <load amount="10000">Salt</load>
                   </vehicle>
                   <vehicle>
                       <licensePlate>MS-C# 2010</licensePlate>
                       <manufacturer>Mercedes-Benz</manufacturer>
                       <load amount="20000">Peanuts</load>
                   </vehicle>
                   <vehicle>
                       <licensePlate>MS-F# 2010</licensePlate>
                       <manufacturer>Peterbilt</manufacturer>
                       <load amount="5000">Bobbleheads</load>
                   </vehicle>
               </fleet>
Dim mackVehicles = From vehicle In fleet...<vehicle> _
Where vehicle.<manufacturer>.Value = "Mack"
For Each vehicle In mackVehicles
    Console.WriteLine(vehicle)
Next

The fleet ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required