org.jdom.output
Class XMLOutputter

java.lang.Object
  |
  +--org.jdom.output.XMLOutputter

public class XMLOutputter
extends java.lang.Object

XMLOutputter takes a JDOM tree and formats it to a stream as XML. This formatter performs typical document formatting. The XML declaration and processing instructions are always on their own lines. Empty elements are printed as and text-only contents are printed as content on a single line. Constructor parameters control the indent amount and whether new lines are printed between elements. For compact machine-readable output pass in an empty string indent and a false for printing new lines.

Version:
1.0
Author:
Brett McLaughlin, Jason Hunter

Constructor Summary
XMLOutputter()
           This will create an XMLOutputter with a two-space indent and new lines on.
XMLOutputter(java.lang.String indent)
           This will create an XMLOutputter with the given indent and new lines on.
XMLOutputter(java.lang.String indent, boolean newlines)
           This will create an XMLOutputter with the given indent and new lines printing only if newlines is true.
 
Method Summary
protected  void indent(java.io.PrintWriter out, int level)
           This will print the proper indent characters for the given indent level.
protected  void maybePrintln(java.io.PrintWriter out)
           This will print a new line only if the newlines flag was set to true
 void output(Document doc, java.io.OutputStream out)
           This will print the Document to the given output stream.
protected  void printAttributes(java.util.List attributes, java.io.PrintWriter out)
           This will handle printing out an Attribute list.
protected  void printDeclaration(Document doc, java.io.PrintWriter out)
           This will print the declaration to the given output stream.
protected  void printDocType(DocType docType, java.io.PrintWriter out)
           This will print the DOCTYPE declaration if one exists.
protected  void printElement(Element element, java.io.PrintWriter out, int indentLevel)
           This will handle printing out an Element, its Attributes, and its value.
protected  void printProcessingInstructions(java.util.List pis, java.io.PrintWriter out)
           This will print the processing instructions to the given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLOutputter

public XMLOutputter()

This will create an XMLOutputter with a two-space indent and new lines on.


XMLOutputter

public XMLOutputter(java.lang.String indent)

This will create an XMLOutputter with the given indent and new lines on.

Parameters:
indent - the indent string, usually some number of spaces

XMLOutputter

public XMLOutputter(java.lang.String indent,
                    boolean newlines)

This will create an XMLOutputter with the given indent and new lines printing only if newlines is true.

Parameters:
indent - the indent String, usually some number of spaces
newlines - true indicates new lines should be printed, else new lines are ignored (compacted).
Method Detail

indent

protected void indent(java.io.PrintWriter out,
                      int level)

This will print the proper indent characters for the given indent level.

Parameters:
out - PrintWriter to write to
level - int indentation level

maybePrintln

protected void maybePrintln(java.io.PrintWriter out)

This will print a new line only if the newlines flag was set to true

Parameters:
out - PrintWriter to write to

output

public void output(Document doc,
                   java.io.OutputStream out)
            throws java.io.IOException

This will print the Document to the given output stream. The characters are printed using UTF-8 encoding.

Parameters:
doc - Document to format.
out - PrintWriter to write to.
Throws:
IOException - - if there's any problem writing.

printDeclaration

protected void printDeclaration(Document doc,
                                java.io.PrintWriter out)

This will print the declaration to the given output stream. Assumes XML version 1.0 since we don't directly know.

Parameters:
docType - DocType whose declaration to write.
out - PrintWriter to write to.

printDocType

protected void printDocType(DocType docType,
                            java.io.PrintWriter out)

This will print the DOCTYPE declaration if one exists.

Parameters:
doc - Document whose declaration to write.
out - PrintWriter to write to.

printProcessingInstructions

protected void printProcessingInstructions(java.util.List pis,
                                           java.io.PrintWriter out)

This will print the processing instructions to the given output stream. Assumes the List contains nothing but ProcessingInstruction objects.

Parameters:
pis - List of ProcessingInstructions to print
out - PrintWriter to write to

printElement

protected void printElement(Element element,
                            java.io.PrintWriter out,
                            int indentLevel)

This will handle printing out an Element, its Attributes, and its value.

Parameters:
element - Element to output.
out - PrintWriter to write to.
indent - int level of indention.

printAttributes

protected void printAttributes(java.util.List attributes,
                               java.io.PrintWriter out)

This will handle printing out an Attribute list.

Parameters:
attributes - List of Attribute objcts
out - PrintWriter to write to


Copyright © 2000 Brett McLaughlin, Jason Hunter. All Rights Reserved.