htmlcleaner惯用法

Common usage

Tipically the following steps are taken:

// create an instance of HtmlCleaner
HtmlCleaner cleaner = new HtmlCleaner();
 
// take default cleaner properties
CleanerProperties props = cleaner.getProperties();
 
// customize cleaner's behaviour with property setters
props.setXXX(...);
 
// Clean HTML taken from simple string, file, URL, input stream, 
// input source or reader. Result is root node of created 
// tree-like structure. Single cleaner instance may be safely used
// multiple times.
TagNode node = cleaner.clean(...);
 
// optionally find parts of the DOM or modify some nodes
TagNode[] myNodes = node.getElementsByXXX(...);
// and/or
Object[] myNodes = node.evaluateXPath(xPathExpression);
// and/or
aNode.removeFromTree();
// and/or
aNode.addAttribute(attName, attValue);
// and/or
aNode.removeAttribute(attName, attValue);
// and/or
cleaner.setInnerHtml(aNode, htmlContent);
 
// serialize a node to a file, output stream, DOM, JDom...
new XXXSerializer(props).writeXmlXXX(aNode, ...);
myJDom = new JDomSerializer(props, true).createJDom(aNode);
myDom = new DomSerializer(props, true).createDOM(aNode);
 

你可能感兴趣的:(html)