如何删除除“src”之外的HTML属性和“alt”在JAVA [英] How to strip HTML attributes except "src" and "alt" in JAVA

查看:190
本文介绍了如何删除除“src”之外的HTML属性和“alt”在JAVA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从字符串中的HTML标签中删除所有属性,除了使用Java的alt和src?

How do I strip all attributes from HTML tags in a string, except "alt" and "src" using Java?

还有..我怎么得到来自字符串中所有src属性的内容?

And further.. how do I get the content from all "src" attributes in the string?

:)

推荐答案

好的,以某种方式解决了这个问题。

OK, solved this somehow.

使用HTMLCleaner库将输入数据解析为有效格式。

Used the HTMLCleaner library to parse the input data to a valid format.

然后我使用DOM解析器迭代所有内容,并删除所有不允许的标签和属性。

Then I use a DOM parser to iterate over everything, and strip all disallowed tags and attributes.

(和一些小丑陋的黑客;))

(and some minor ugly hacks;) )

这是一项很多工作。

这篇关于如何删除除“src”之外的HTML属性和“alt”在JAVA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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