Write HTML to string

前端 未结 18 1543
一生所求
一生所求 2020-12-13 00:04

I have code like this. Is there a way to make it easier to write and maintain? Using C# .NET 3.5.

string header(string title)
{
    StringWriter s = new Stri         


        
18条回答
  •  臣服心动
    2020-12-13 00:41

    You could use System.Xml.Linq objects. They were totally redesigned from the old System.Xml days which made constructing XML from scratch really annoying.

    Other than the doctype I guess, you could easily do something like:

    var html = new XElement("html",
        new XElement("head",
            new XElement("title", "My Page")
        ),
        new XElement("body",
            "this is some text"
        )
    );
    

提交回复
热议问题