XElement.Descendants : XElement « System.Xml.Linq « C# / C Sharp by API






XElement.Descendants

   


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

class Program {
    static void Main(string[] args) {
        XElement xml = XElement.Load("Employee.xml");
        var query = from p in xml.Descendants("person")
                    join s in xml.Descendants("id")
                    on (int)p.Element("id") equals (int)s.Attribute("id")
                    select new {
                        FirstName = p.Element("firstname").Value,
                        LastName = p.Element("lastname").Value,
                        Amount = s.Attribute("salaryyear").Value
                    };
        foreach (var record in query) {
            Console.WriteLine("Employee: {0} {1}, Salary {2}", record.FirstName,
                                                            record.LastName,
                                                            record.Amount);
        }
    }
}

   
    
    
  








Related examples in the same category

1.new XElement
2.XElement.AddFirst
3.XElement.Ancestors()
4.XElement.AncestorsAndSelf()
5.XElement.AncestorsAndSelf(String tagName)
6.XElement.Attribute
7.XElement.Changed
8.XElement.Changing
9.XElement.Descendants("firstname").First()
10.XElement.Elements
11.XElement.First
12.XElement.FirstAttribute
13.XElement.GetSchemaInfo()
14.XElement.HasAttributes
15.XElement.HasElements
16.XElement.Load(String fileName)
17.XElement.Nodes()
18.XElement.Parent
19.XElement.Parse(String xml value)
20.XElement.Remove
21.XElement.RemoveAll
22.XElement.Save(String fileName)
23.XElement.SetAttributeValue
24.XElement.SetElementValue