1

I want to format html code with C#. From this:

<!DOCTYPE html><html><head><title>Hello World!</title></head><body><h1>Hi, HTML!</h1></body></html>

I want this:

<!DOCTYPE html>
<html>
    <head>
        <title>Hello World!</title>
    </head>
    <body>
        <h1>Hi, HTML!</h1>
    </body>
</html>

I tried: string result = System.Xml.Linq.XElement.Parse(source).ToString(); And this works, but if I try this with Google website code, it throws some exceptions because doctypeisn't written correctly.

How can I format HTML code without HTML syntax error check?

Can anyone help me? Thanks in advance!

0 Answers0