重新格式化(即“美化")HTML [英] Reformat (i.e. "Beautify") Html

查看:148
本文介绍了重新格式化(即“美化")HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨;

是否有人知道任何合适的源代码示例(以VB或C#格式),以重新格式化HTML源并输出HTML的纯净"版本,该版本已正确缩进并在相关标记处换行了?

我发现很多网站都可以这样做,但是我需要能够将此功能集成到我的应用程序中.

我已经尝试过自己实施此操作,但无法使其正常工作-导致我的脑袋准备爆炸了!

任何指针将不胜感激.

在此先感谢

亲切的问候

Dave

Hi;

Does anyone know of any decent source code examples (in either VB or C#), to reformat HTML source and output a "cleaned" version of the HTML, that is correctly indented and line breaked at the relevant tags?

I have found plently of websites that will do same, however I need to be able to integrate this functionality in my application.

I have tried implementing this myself, yet can not get it to work correctly - to the point that my head is ready to explode!

Any pointers would be greatly appreciated.

Thanks in advance

Kind Regards

Dave

推荐答案

您可以将问题分为两种情况:原始文件是否为格式正确的XML.确实是这样(如果与XHTML模式是否兼容甚至无关紧要),问题就很容易解决:使用类System.Xml.XmlTextReader/System.Xml.XmlTextWriterSystem.Xml.XmlDocument.如果不是,则这是一项无聊的手动任务,无法100%保证结果.搜索类似这样的内容: http://en.lmgtfy.com/?q=html+tidy [ ^ ].

—SA
You could split a problem in two big cases: if original file a well-formed XML or not. It it is (if does not even matter if it is compliant with XHTML schema or not), the problem is solved very easy: use the classes System.Xml.XmlTextReader/System.Xml.XmlTextWriter or System.Xml.XmlDocument. If it is not, this is a boring manual task without 100% guarantee of the result. Search for something like this: http://en.lmgtfy.com/?q=html+tidy[^].

—SA


这篇关于重新格式化(即“美化")HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆