I am programming in C#. I have some data that I want to write to an HTML file as a table of 3 columns and an unknown number of rows.
Then I display that file in a web browser.
Currently this is all done by brute force. The C# code writes out the <HTML> tag and all the following header tags. It writes the <TABLE> tag. It loops through the data, writing each line of the table, adding appropriate <TR>...</TR> and <TD>...</TD> tags. It then closes the table with a </TABLE> tag, writes some footer information, and finally ends the file with a </HTML> tag.
There's got to be a better way.
This code works, but it's difficult to maintain.
I know PHP has a nice way of dealing with this, But I'm not using PHP, I'm using C#.
I've seen XSLT transformations that outputs nice HTML code, but my input isn't XML.
Is there a good way to deal with this in C#? Where I can create some sort of template that's easy to understand and maintain? A template that conveys the idea, "I want the output to be a HTML file which has a table of 3 columns"?