I have a .NET console application that needs to generate some HTML files. I could just construct the HTML in a StringBuilder and write the contents out to a file, but I was
One way you could do this is create a XSL file as the template, serialise your customDataObject
as XML then perform a transform to generate the required HTML.
Update: Whilst I like (and do use) the string replacement method advocated by other folks here, there is a certain flexibility to using XML/XSL. Say your object has a property that is a list, for example an order object with a list of line item objects, you pretty much have to burn into your code the logic that has to render the line items.
With XSL all you do is pass the serialised order object XML to the XSL and let the XSL handle whatever HTML it needs to generate. This means you can often edit the XSL in place or have variants (order summary, detailed order etc) without adding extra code to your app with all the extra hassle of rebuild/deploy.
But then it all depends on the complexity of what you need to render, for some jobs string replacement is more obvious, for others XSL is the way. As I said, we use both.