LINQ to XML in VB.NET

LINQ to XML is an in-memory XML programming API designed specifically to take advantage of Language-Integrated Query (LINQ). Although you can call the LINQ APIs directly, only Visual Basic enables you to declare XML literals and directly access XML axis properties.

<CompanyInfo>
  <DepartmentInfo>
    <Department ID="1">
      <Deptno>10</Deptno>
      <DeptName>IT</DeptName>
      <Location>New York</Location>
      <EmployeeInfo>
        <Employee ID="1">
          <Empno>1001</Empno>
          <LastName>Kim</LastName>
          <Salary>2000</Salary>
          <Deptno>10</Deptno>
        </Employee>
      </EmployeeInfo>
    </Department>
  </DepartmentInfo>
</CompanyInfo>

VB Example

Imports System.Linq

Dim doc As XDocument

doc = XDocument.Load("data.xml")

Dim qx = From xe In doc.Descendants.Elements("Employee") _
         Select New With { _
                    .ID = xe.Attribute("ID").Value, _
                    .Empno = xe.Element("Empno").Value, _
                    .LastName = xe.Element("LastName").Value, _
                    .Salary = xe.Element("Salary").Value, _
                    .Deptno = xe.Element("Deptno").Value _
                    }
                                        
Me.GridView1.DataSource = qx.ToList