如何在Java中设置`invalidAttributeNamePrefix`值?

时间:2018-08-30 16:15:07

标签: htmlcleaner

假设我正在使用HtmlCleanerv2.18)清理一些html,并且我想将属性invalidAttributeNamePrefix(请参见Cleaner parameters)设置为某个值 ie: data-

这样,HTML中的属性my-custom-attr="my-value"将被转换为data-my-custom-attr="my-value"

我该怎么做??我找不到Java usage的任何示例。

您可以将此代码作为参考:

HtmlCleaner cleaner = new HtmlCleaner();
CleanerProperties properties = cleaner.getProperties();
properties.setOmitComments(true);
// properties.setInvalidAttributeNamePrefix("data-"); there is no such method

// html is a declared variable which contains some html content
TagNode rootTagNode = cleaner.clean(html);
XmlSerializer xmlSerializer = new PrettyXmlSerializer(properties);
String cleanedHtml = xmlSerializer.getAsString(rootTagNode);

1 个答案:

答案 0 :(得分:0)

升级到version 2.22可解决此问题。

现在可以完成

// ...
properties.setInvalidXmlAttributeNamePrefix("data-");
//...