Use Linq query to get XML document elements : Query : XML LINQ C# Source Code


Custom Search

C# Source Code » XML LINQ » Query »

 

Use Linq query to get XML document elements








    
 

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");
        XElement html = new XElement("HTML",
                                new XElement("BODY",
                                    new XElement("TABLE",
                                        new XElement("TH", "ID"),
                                        new XElement("TH", "Full Name"),
                                        new XElement("TH", "Role"),
                                            from p in xml.Descendants("person")
                                            join r in xml.Descendants("role") on (int)p.Element("idrole") equals (int)r.Element("id")
                                            select new XElement("TR",
                                                            new XElement("TD", p.Element("id").Value),
                                                            new XElement("TD", p.Element("firstname").Value + " " + p.Element("lastname").Value),
                                                            new XElement("TD", r.Element("roledescription").Value)))));

        html.Save(@"C:\People.html");
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo XML LINQ
» Query