如何验证文本是否为有效的 HTML?

发布于 2024-08-05 03:43:25 字数 298 浏览 14 评论 0原文

我使用的是旧版本的 Telerik Editor 控件,并将输入的文本存储在 SQL 数据库中,然后显示 HTML。 ASP.NET (2.0) 中有什么方法可以在保存到数据库之前验证字符串是否为有效的 HTML?谢谢!

I'm using an older version of Telerik's Editor control, and storing the text that's input in a SQL database, then displaying the HTML later. Is there any way in ASP.NET (2.0) to validate a string as being valid HTML before saving to my database? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

酷炫老祖宗 2024-08-12 03:43:25

您可以从这里开始:

C# XHTML Validator

或者在这里(正则表达式):

正则表达式库 - 标记为“HTML”的条目

或者在这里 ;)

谷歌

四叶草在未来唯美盛开 2024-08-12 03:43:25

正则表达式可能很慢并且占用 CPU 资源,W3C 有一个开源工具,您可以使用 http://www .w3.org/QA/Tools/

regexes can be slow and cpu intensive, W3C has an open source tool that you could use http://www.w3.org/QA/Tools/

幸福%小乖 2024-08-12 03:43:25

该编辑器有一个内置的验证器对话框,可以连接到在线 W3 工具来检查当前内容。您可以在此处查看示例 - XHTML 验证器示例

The editor has a built-in validator dialog that connects to the online W3 tool to check the current content. You can see an example here - XHTML Validator example

不知在何时 2024-08-12 03:43:25

嗯 - 您使用的是哪个版本(“旧版本”不是很具体)?

在 .Net 1.1/2.0 版本中(我认为是 2004/2005 年的版本 3.x/4.x),编辑器 API 包含一个读/写属性 Html,允许您设置内容作为 HTML,还可以检索它以存储在任何位置,以及只读属性 Xhtml 确保您获得兼容的、基于 XML 的内容(还有像 这样的属性>SaveAsXhtml 以确保如果您写回文件,它将采用 XHTML 格式)。

我明白,如果您的页面向 HTML 4.0 提供内容,那么您可能会遇到一些封闭标记的问题(
、 ETC)。

请记住,有效的 HTML 和干净的 HTML 之间是有区别的。

我看到 当前版本 不再具有 Xhtml 属性,并且 Html 属性已被弃用,取而代之的是 Content 属性,所以我假设这个默认情况下输出有效的 Xhtml。

Hmm - which version are you using ("older version" isn't terribly specific)?

In the .Net 1.1/2.0 versions (I think about version 3.x/4.x from 2004/2005) the editor API consisted of a read/write property Html that allowed you to set the content as HTML, and also retrieve it for storing where ever, and a read only property Xhtml that ensures the you get compliant, XML based content (there were also properties like SaveAsXhtml to ensure that if you were writing back to the file, it would be in XHTML).

I appreciate that if your page is serving content to HTML 4.0 then you might have some issues with closed tags (<br />, <img />, etc).

Remember there's a difference between valid HTML and clean HTML.

I see that the current version no longer has an Xhtml property, and that the Html property is deprecated in favour of the Content property, so I assume this is outputting valid Xhtml by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文