需要的工具,HTML格式(缩进,加空格) [英] Need tool to format html (indent, add whitespace)

查看:235
本文介绍了需要的工具,HTML格式(缩进,加空格)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个.NET项目生成HTML。

I am working on a .net project that generates html.

在生成的HTML字符串,则没有空格或缩进。这使得理解生成的HTML困难。

When the html string is generated, the is no whitespace or indenting. This makes understanding the generated html difficult.

有没有一种工具,将生成的html我的字符串格式化,这样它看起来不错?

Is there a tool that will take my string of generated html and format it so that it looks nice?

推荐答案

如果您正在生成HTML自己,这应该是有效的XML。

If you're generating the HTML yourself, it should be valid XML.

因此​​,您可以使用的XDocument 类进行格式化。

Therefore, you can use the XDocument class to format it.

您可以建立内部的HTML的的XDocument ,然后调用的ToString(),它会自动格式化HTML给你。

You can build the HTML inside an XDocument, then call ToString(), which will automatically format the HTML for you.

此外,的XDocument应该是更容易比手工字符串连接使用,将本质上保护您免受大多数(但不是全部)XSS攻击。

In addition, XDocument should be much easier to use than manual string concatenation, and will intrinsically protect you from most (but not all) XSS attacks.

这篇关于需要的工具,HTML格式(缩进,加空格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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