A Simple XML Query Using LINQ to XML : Query : XML LINQ C# Source Code


Custom Search

C# Source Code » XML LINQ » Query »

 

A Simple XML Query Using LINQ to XML








    
 

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

public class MainClass {
    public static void Main() {

        XElement books = XElement.Parse(
          @"<books>
        <book>
          <title>P</title>
          <author>J</author>
        </book>
        <book>
          <title>W</title>
          <author>B</author>
        </book>
        <book>
          <title>C</title>
          <author>A</author>
        </book>
    </books>");

        var titles =
         from book in books.Elements("book")
         where (string)book.Element("author") == "J"
         select book.Element("title");

        foreach (var title in titles)
            Console.WriteLine(title.Value);
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo XML LINQ
» Query