`
gstarwd
  • 浏览: 1538301 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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)
;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics