Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27196

LINQ to XML Query in VB

$
0
0
Ok, Im new to LINQ to XML and need some help getting my query set up. I have googled for hours and it seems every diffrent website has a diffrent way of doing it and I am getting really really confused. Here is my XML:
Code:

<?xml version = "1.0"?>
<booking>
    <client>
        <id>0001</id>
        <name>Jack Loper</name>
        <numofseats>3</numofseats>
        <seats>C1C2C3</seats>
        <cost>30</cost>
    </client>
    <client>
        <id>0002</id>
        <name>Joe Bloggs</name>
        <numofseats>1</numofseats>
        <seats>D8</seats>
        <cost>10</cost>
    </client>
</booking>

Now, I have sucessfully got my document loaded into VB:

Code:

Dim BookingDatabase As XDocument
BookingDatabase = XDocument.Load(My.Application.Info.DirectoryPath & "\Booking_Database.xml")

I would like the output from my query to be:

0001 Jack Loper
0002 Joe Bloggs

How would I set up my query? At the moment I have this, but I have no idea what the hell I am actually doing:

Code:

Dim query = From ex In BookingDatabase.Descendants.Elements("client")
                    Select id = ex.Attribute("id").Value
        For Each ex In query
            Console.WriteLine(ex)
        Next

If you could explain each step, that would be nice and helpful :) . Thanks

Viewing all articles
Browse latest Browse all 27196

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>