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.
|
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 |
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 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.TreeWalkerImpl
public void setNodeFilter(org.w3c.dom.traversal.NodeFilter nodeFilter)
nodeFilter
- the filter used to screen nodesTreeWalkerImpl
public void setEntityReferenceExpansion(boolean entityReferenceExpansion)
entityReferenceExpansion
- the flag to determine whether the children of entity reference
nodes are visible to TreeWalker.TreeWalkerImpl
public 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 writeToFile(String filePath) throws IOException
filePath
- the target file pathIOException
public void writeToFile(File file) throws IOException
file
- the target FileIOException
public void writeToFile(String filePath, String encode) throws IOException
filePath
- the target file pathencode
- the target encodingIOException
public void writeToFile(File file, String encode) throws IOException
file
- the target fileencode
- the target encodingIOException