use Linq to query an XML document : Query : XML LINQ C# Source Code


Custom Search

C# Source Code » XML LINQ » Query »

 

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)
          )
        );
        Console.WriteLine(xml);
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo XML LINQ
» Query