c#自动修复缺损和不规范的html
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; } } } }
桂棹兮兰桨,击空明兮溯流光。