private string fixHTML(string html) { using (var reader = new SgmlReader()) { reader.DocType = "HTML"; reader.InputStream = new StringReader(html); using (var sw = new StringWriter()) { using (var writer = new XmlTextWriter(sw)) { writer.Formatting = Formatting.Indented; while (reader.Read()) { if (reader.NodeType != XmlNodeType.Whitespace) { writer.WriteNode(reader, true); } } var sb = new StringBuilder(); var doc = new XPathDocument(new StringReader(sw.ToString())); var nav = doc.CreateNavigator(); var result = nav.SelectSingleNode("/").OuterXml; return result; } } } }