Java HTML 解析器/验证器

发布于 2024-10-08 21:05:38 字数 316 浏览 0 评论 0原文

我们允许人们在我们类似 wiki 的网站上输入 HTML 代码。但只有有限的 HTML 子集不会影响我们的样式并且不允许恶意 JavaScript 代码。服务器端有没有好的Java库来保证输入的代码有效?

我们尝试创建一个 XML 架构文档来进行验证。唯一的问题是我们用来验证的库返回了神秘的错误消息。我想要的是验证库实际上解决问题(如果元素中添加了 style="" 属性,删除它)。如果修复它并不容易,至少允许我向用户报告一条消息,其中包含错误的位置(我可以从中提供一条不错的消息的错误代码很好,甚至可能更好)。

We allow people to enter HTML code on our wiki-like site. But only a limited subset of HTML to not affect our styling and not allow malicious javascript code. Is there a good Java library on the server side to ensure that the code entered is valid?

We tried creating an XML Schema document to validate against. The only issue there is the libraries we used to validate gave back cryptic error messages. What I want is for the validation library to actually fix the issue (if there was a style="" attribute added to an element, remove it). If fixing it is not easy, at least allow me to report a message to the user with the location of the error (an error code that I can present a nice message from is fine, probably even preferable).

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

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

发布评论

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

评论(1

毁梦 2024-10-15 21:05:38

尝试 JSoup。我认为这就是您正在寻找的:
JSoup

Try JSoup. I think this is what you're looking for:
JSoup

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