static void Main() { XElement root = XmlSampleData.GetElement(); var query = root.Element("users").Elements() .Select(user => new { Name = (string)user.Attribute("name"), UserType = (string)user.Attribute("type") }); foreach (var user in query) { Console.WriteLine("{0}: {1}", user.Name, user.UserType); } }
static void Main() { XElement root = XmlSampleData.GetElement(); var query = from defect in root.Descendants("defect") join user in root.Descendants("user") on(int?) defect.Attribute("assigned-to") equals (int) user.Attribute("id") join project in root.Descendants("project") on(int) defect.Attribute("project") equals (int) project.Attribute("id") where (string)defect.Attribute("status") != "Closed" select new { ID = (int)defect.Attribute("id"), Project = (string)project.Attribute("name"), Assignee = (string)user.Attribute("name") }; foreach (var defect in query) { Console.WriteLine("{0}: {1}/{2}", defect.ID, defect.Project, defect.Assignee); } }
static void Main() { Console.WriteLine(XmlSampleData.GetElement()); }