Query XML: All descendants in document : Query « XML LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Text;

    class Program
    {
        static void Main(string[] args)
        {
            string xmlFileName = "e.xml";
            XDocument customers = XDocument.Load(xmlFileName);

            var queryResult = from c in customers.Descendants() select c.Name;
            foreach (var item in queryResult)
            {
                Console.WriteLine(item);
            }
        }
    }








31.4.Query
31.4.1.Query XML by select an element
31.4.2.Query XML: All descendants in document
31.4.3.Query XML: All distinct descendants in document
31.4.4.Query XML: Attributes named 'Company'
31.4.5.Query XML: Attributes of descendants named 'customer'
31.4.6.Query XML: Descendants named 'customer'
31.4.7.Query XML: Earliest year in which orders were placed
31.4.8.Query XML: Values of customer attributes named 'Company'
31.4.9.Query XML: Values of descendant attributes named 'orderYear'
31.4.10.Query XML: attributes named 'orderYear'
31.4.11.Using Linq To query Xml