public class DomPrintUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
DomPrintUtil.AttributeFilter
AttributeFilter defines the behavior of a filter that is used for
converting attributes of each Element into String.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
UTF8
Default encoding of this utility.
|
| Constructor and Description |
|---|
DomPrintUtil(Document document)
Constructor of DOM print utility.
|
DomPrintUtil(Node rootNode)
Constructor of DOM print utility.
|
| Modifier and Type | Method and Description |
|---|---|
void |
setAttrFilter(DomPrintUtil.AttributeFilter attrFilter)
Set AttributeFilter to define the behavior for printing attributes of
each Element.
|
void |
setEntityReferenceExpansion(boolean entityReferenceExpansion)
Set the entity reference expansion flag to TreeWalker used in the
utility.
|
void |
setEscapeTagBracket(boolean escapeTagBracket)
Determine to escape Tag bracket ('<','>') or not.
|
void |
setHTML5(boolean isHTML5)
Set true if the document is HTML5.
|
void |
setIndent(boolean indent)
Set the number of space characters used for indent
|
void |
setNodeFilter(org.w3c.dom.traversal.NodeFilter nodeFilter)
Set NodeFilter to TreeWalker used in the utility.
|
void |
setWhatToShow(int whatToShow)
Set whatToShow attribute to TreeWalker used in the utility.
|
String |
toString() |
String |
toXMLString()
Returns XML text converted from the target DOM
|
void |
writeToFile(File file)
Print out the target Document.
|
void |
writeToFile(File file,
String encode)
Print out the target Document in specified encoding
|
void |
writeToFile(String filePath)
Print out the target Document.
|
void |
writeToFile(String filePath,
String encode)
Print out the target Document in specified encoding
|
public static final String UTF8
public DomPrintUtil(Document document)
document - the target documentpublic DomPrintUtil(Node rootNode)
root - Node the target root Nodepublic String toXMLString()
public void setWhatToShow(int whatToShow)
whatToShow - the attribute determines which types of node are presented via
the TreeWalker. The values are defined in the NodeFilter
interface.TreeWalkerImplpublic void setNodeFilter(org.w3c.dom.traversal.NodeFilter nodeFilter)
nodeFilter - the filter used to screen nodesTreeWalkerImplpublic void setEntityReferenceExpansion(boolean entityReferenceExpansion)
entityReferenceExpansion - the flag to determine whether the children of entity reference
nodes are visible to TreeWalker.TreeWalkerImplpublic void setIndent(boolean indent)
indent - the number of space characters used for indentpublic void setEscapeTagBracket(boolean escapeTagBracket)
escapeTagBracket - if true, print Tag bracket as escaped format (
'<',
'>')public void setAttrFilter(DomPrintUtil.AttributeFilter attrFilter)
attrFilter - the AttributeFilter to setpublic void setHTML5(boolean isHTML5)
isHTML5 - public void writeToFile(String filePath) throws IOException
filePath - the target file pathIOExceptionpublic void writeToFile(File file) throws IOException
file - the target FileIOExceptionpublic void writeToFile(String filePath, String encode) throws IOException
filePath - the target file pathencode - the target encodingIOExceptionpublic void writeToFile(File file, String encode) throws IOException
file - the target fileencode - the target encodingIOException