RosettaCodeData/Task/Create-an-HTML-table/C-sharp/create-an-html-table-2.cs

48 lines
777 B
C#
Raw Permalink Normal View History

2014-04-02 16:56:35 +00:00
using System;
using System.Text;
using System.Xml;
namespace N
{
public class T
{
public static void Main()
{
2015-02-20 00:35:01 -05:00
var headers = new [] { "", "X", "Y", "Z" };
2014-04-02 16:56:35 +00:00
2015-02-20 00:35:01 -05:00
var cols = headers.Select(name =>
new XElement(
2014-04-02 16:56:35 +00:00
"th",
name,
new XAttribute("text-align", "center")
)
);
2015-02-20 00:35:01 -05:00
var rows = Enumerable.Range(0, 4).Select(ri =>
new XElement(
"tr",
new XElement("td", ri),
Enumerable.Range(0, 4).Select(ci =>
new XElement(
"td",
ci,
new XAttribute("text-align", "center")
)
2014-04-02 16:56:35 +00:00
)
2015-02-20 00:35:01 -05:00
)
);
2014-04-02 16:56:35 +00:00
2015-02-20 00:35:01 -05:00
var xml = new XElement(
2014-04-02 16:56:35 +00:00
"table",
2015-02-20 00:35:01 -05:00
new XElement(
2014-04-02 16:56:35 +00:00
"thead",
2015-02-20 00:35:01 -05:00
new XElement("tr", cols),
2014-04-02 16:56:35 +00:00
new XElement("tbody", rows)
)
);
Console.WriteLine(xml.ToString());
}
}
}