所以,我使用
HtmlAgilityPack生成html并且它工作正常,但是html文本没有缩进.我可以得到缩进的XML,但我需要HTML.有办法吗?
HtmlDocument doc = new HtmlDocument(); // gen html HtmlNode table = doc.CreateElement("table"); table.Attributes.Add("class","tableClass"); HtmlNode tr = doc.CreateElement("tr"); table.ChildNodes.Append(tr); HtmlNode td = doc.CreateElement("td"); td.InnerHtml = "—"; tr.ChildNodes.Append(td); // write text,no indent :( using(StreamWriter sw = new StreamWriter("table.html")) { table.Writeto(sw); } // write xml,nicely indented but it's XML! XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.Indent = true; settings.ConformanceLevel = ConformanceLevel.Fragment; using (XmlWriter xw = XmlTextWriter.Create("table.xml",settings)) { table.Writeto(xw); }
解决方法
据我所知,HtmlAgilityPack无法做到这一点.但你可以通过类似问题提出的html整洁包看看:
> Html Agility Pack: make code look
neat
> Which is the best HTML tidy pack? Is there any option in HTML agility pack to make HTML webpage tidy?
原文地址:https://www.jb51.cc/csharp/91372.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。