C# 和编写 HTML - 最好的方法?
我需要从纯文本构建 HTML 文档并将其显示在 webBrowser 中。我正在考虑更好的方法 - 我可以看到 System.Web.UI 中有 HTMLTextWriter 但我无法引用这个命名空间,有人可以建议吗? 谢谢
I would need to build a HTML document from plain text and display it in webBrowser. I was thinking of better way - I can see there is HTMLTextWriter in System.Web.UI but I cannot reference this namespace, could anyone advice?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的应用程序要求,您可以托管自己的浏览器控件并构建内容:
Depending on your application requirements you could host your own browser control and build the content:
最简单的方法是使用普通的
XmlWriter
(或者,如果您需要更复杂的构建而不仅仅是编写元素流,则使用XmlDocument
或XDocument
)输出 XHTML。如果您想使用 System.Web.UI 类,则需要从项目中引用 System.Web.dll 。不过,我不会推荐它,因为它不会给您带来太多好处,而且它不包含在 .NET Client Profile 中(您将来可能需要使用它,尤其是在 .NET 4 中)。
Simplest way is to use plain
XmlWriter
(or, if you need more complex building than just writing a stream of elements,XmlDocument
orXDocument
) and output XHTML.If you want to use
System.Web.UI
classes, you need to referenceSystem.Web.dll
from your project. I wouldn't recommend it, though, as it won't buy you much, and it is not included in the .NET Client Profile (which you might want to use in the future, especially with .NET 4).