Write HTML to string

前端 未结 18 1510
一生所求
一生所求 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:37

    HSharp is a library used to analyse markup language like HTML easily and fastly. Install: PM> Install-Package Obisoft.HSharp

            var Document = new HDoc(DocumentOptions.BasicHTML);
            Document["html"]["body"].AddChild("div");
            Document["html"]["body"]["div"].AddChild("a", new HProp("href", "/#"));
            Document["html"]["body"]["div"].AddChild("table");
            Document["html"]["body"]["div"]["table"].AddChildren(
             new HTag("tr"),
             new HTag("tr", "SomeText"),
             new HTag("tr", new HTag("td")));
            var Result = Document.GenerateHTML();
            Console.WriteLine(Result);
    

    and output:

    
    
    
    Example 
    
    
    
    SomeText

提交回复
热议问题