Coding Fun Html Part 6 Transforming XML to HTML table using LINQ to XML

Part 6 Transforming XML to HTML table using LINQ to XML





In Part 5 of LINQ to XML tutorial, we discussed, how to tranform XML to CSV.

In this video, we will discuss transforming XML to HTML table.

Text version of the video

Slides

LINQ to SQL Tutorial – All Text Articles &…

Tags: , , , , , , , , , , , , , , ,

6 thoughts on “Part 6 Transforming XML to HTML table using LINQ to XML”

  1. Paul Sih says:

    Please help. Get error "Object reference not set to an instance of object"

    xel = XElement.Parse("<Employees>" +
    "<Employee>" +
    "<ID>001</ID>" +
    "<FirstName>John</FirstName>" +
    "<LastName>Wick</LastName>" +
    "<BirthYear>1983</BirthYear>" +
    "</Employee>" +
    "<Employee>" +
    "<ID>002</ID>" +
    "<FirstName>John</FirstName>" +
    "<LastName>McClane</LastName>" +
    "<BirthYear>1982</BirthYear>" +
    "</Employee>" +
    "</Employees>");

    XDocument xdoc = new XDocument(new XElement("table", new XAttribute("border", 1),
    new XElement("thead",
    new XElement("tr",
    new XElement("th", "ID"),
    new XElement("th", "Firstname"),
    new XElement("th", "Lastname"),
    new XElement("th", "BirthYear")
    )
    ),

    new XElement("tbody",
    from emp in xel.Descendants("Employee")
    select new XElement("tr",
    new XElement("td", xel.Element("ID").Value),
    new XElement("td", xel.Element("FirstName").Value),
    new XElement("td", xel.Element("LastName").Value),
    new XElement("td", xel.Element("BirthYear").Value)
    )
    )
    )
    );

  2. Exactly what I looked for. Thanks.

  3. sarvesh says:

    SIR, PLEASE PROVIDE TUTORIAL FOR LOCALISATION & GLOBALISATION IN ASP.NET VIDEO SERIES.ITS VERY DIFFICULT TO UNDERSTAND THE CONCEPT.THANKS.

  4. Yogesh Patel says:

    Can you please explain in which scenario, thia kind of transformation method is useful?

Leave a Reply

Your email address will not be published. Required fields are marked *