All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.kvisco.xml.XMLPrinter

com.kvisco.xml.XMLPrinter

public class XMLPrinter
A class for printing XML nodes

Author:
Keith Visco

Variable Index

 o DEFAULT_INDENT
The default indent size

Constructor Index

 o XMLPrinter(PrintWriter)
Creates a new XML Printer using the given PrintWriter for output
 o XMLPrinter(PrintWriter, int)
Creates a new XML Printer using the given PrintWriter for output, and nodes are indenting using the specified indent size

Method Index

 o print(Node)
Prints the given Node
 o printCDATASection(String)
Prints the given Data as a CDATA section
 o printClosingTag(String)
prints the closing tag using the given name
 o printComment(String)
Prints the given data as a comment
 o printDoctype(DocumentType)
 o printEmptyElement(String, NamedNodeMap)
Prints an empty element with the given name and attributes
 o printEntityReference(String)
prints the entity reference with the given name
 o printProcessingInstruction(String, String)
Prints the processing instruction
 o printStartTag(String, NamedNodeMap)
Prints the Start of an element
 o printText(String)
 o printXMLDeclaration(String, String)
prints the XML declaration
 o setIndentSize(int)
Sets the indent size
 o setUnescapeCDATA(boolean)
Sets whether or not to "unwrap" CDATA Sections when printing.
 o setUseEmptyElementShorthand(boolean)
 o setUseFormat(boolean)
Sets whether or not this XMLPrinter should add whitespace to pretty print the XML tree

Variables

 o DEFAULT_INDENT
 public static final int DEFAULT_INDENT
The default indent size

Constructors

 o XMLPrinter
 public XMLPrinter(PrintWriter writer)
Creates a new XML Printer using the given PrintWriter for output

Parameters:
writer - the PrintWriter to use for output
 o XMLPrinter
 public XMLPrinter(PrintWriter writer,
                   int indent)
Creates a new XML Printer using the given PrintWriter for output, and nodes are indenting using the specified indent size

Parameters:
writer - the PrintWriter to use for output
indent - the number of spaces to indent

Methods

 o print
 public void print(Node node)
Prints the given Node

Parameters:
node - the Node to print
 o printCDATASection
 public void printCDATASection(String data)
Prints the given Data as a CDATA section

 o printClosingTag
 public void printClosingTag(String name)
prints the closing tag using the given name

Parameters:
name - the name of the element to print a closing tag for
 o printComment
 public void printComment(String data)
Prints the given data as a comment

Parameters:
data - the character data to print as a comment
 o printDoctype
 public void printDoctype(DocumentType docType)
 o printEmptyElement
 public void printEmptyElement(String name,
                               NamedNodeMap attributes)
Prints an empty element with the given name and attributes

Parameters:
name - the element name
attributes - the element's attlist
 o printEntityReference
 public void printEntityReference(String entityName)
prints the entity reference with the given name

Parameters:
the - name of the entity reference
 o printProcessingInstruction
 public void printProcessingInstruction(String target,
                                        String data)
Prints the processing instruction

Parameters:
target, - the pi target
data - the contents of the pi
 o printStartTag
 public void printStartTag(String name,
                           NamedNodeMap attributes)
Prints the Start of an element

Parameters:
name - the element name
attributes - the element's attlist
 o printText
 public void printText(String data)
 o printXMLDeclaration
 public void printXMLDeclaration(String version,
                                 String encoding)
prints the XML declaration

Parameters:
version - the xml version
encoding, - the character encoding. If null, UTF-8 is the default encoding.
 o setIndentSize
 public void setIndentSize(int indent)
Sets the indent size

Parameters:
indent - the number of spaces to indent
 o setUnescapeCDATA
 public void setUnescapeCDATA(boolean unescape)
Sets whether or not to "unwrap" CDATA Sections when printing. By Default CDATA Sections are left as is.

Parameters:
unescape - the boolean indicating whether or not to unescape CDATA Sections
 o setUseEmptyElementShorthand
 public void setUseEmptyElementShorthand(boolean useShorthand)
 o setUseFormat
 public void setUseFormat(boolean useFormat)
Sets whether or not this XMLPrinter should add whitespace to pretty print the XML tree

Parameters:
useFormat - a boolean to indicate whether to allow the XMLPrinter to add whitespace to the XML tree. (false by default)

All Packages  Class Hierarchy  This Package  Previous  Next  Index