use Linq to query an XML document

using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;

static class HelloLinqToXml {
    static void Main() {
        var books = new[] {
      new {Title="A", Publisher="M", Year=2005 },
      new {Title="W", Publisher="M", Year=2006 },
      new {Title="R", Publisher="M", Year=2006 }
        XElement xml = new XElement("books",
          from book in books
          where book.Year == 2006
          select new XElement("book",
            new XAttribute("title", book.Title),
            new XElement("publisher", book.Publisher)


This entry was posted in XML LINQ. Bookmark the permalink.