Mega Code Archive

 
Categories / VB.Net / XML LINQ
 

Creating new Xml element in the query

Imports System Imports System.Reflection Imports System.Xml Module Module1     Sub Main()         Dim xml As XElement = XElement.Load("People.xml")         Dim query = From p In xml.Descendants("person"), s In xml.Descendants("id") _             Where p.Element("id").Value = s.Attribute("id").Value _             Select New With {.FirstName = p.Element("firstname").Value, _                                 .LastName = p.Element("lastname").Value, _                                 .Amount = s.Attribute("salar").Value}         For Each record In query             Console.WriteLine("Person: {0} {1}, Salary {2}", record.FirstName, _                                                             record.LastName, _                                                             record.Amount)         Next     End Sub End Module