查看jsoup-它应该以优雅的方式处理所有必要的任务。
[编辑]
以下是您所需操作的完整示例:
// Load and parse the document fragment.File f = new File("myfile.html"); // See also Jsoup#parseBodyFragment(s)document doc = Jsoup.parse(f, "UTF-8", "http://example.com");// Remove all script and style elements and those of class "hidden".doc.select("script, style, .hidden").remove();// Remove all style and event-handler attributes from all elements.Elements all = doc.select("*");for (Element el : all) { for (Attribute attr : el.attributes()) { String attrKey = attr.getKey(); if (attrKey.equals("style") || attrKey.startsWith("on")) { el.removeAttr(attrKey); } }}// See also - doc.select("*").removeAttr("style");您将要确保属性名称等大小写无关紧要,但这应该是您所需要的大部分。



