假设我正在使用HtmlCleaner(v2.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);
答案 0 :(得分:0)