Format#getPrettyFormat(). For whitespace-normalized
output, use Format#getCompactFormat().
There are methods to print any of
the standard JDOM classes, including Document and Element, to either a Writer
or an OutputStreamoutput(.
Warning
When outputting to a Writer, make sure
the writer's encoding matches the encoding setting in the Format object. This
ensures the encoding in which the content is written (controlled by the
Writer configuration) matches the encoding placed in the document's XML
declaration (controlled by the XMLOutputter). Because a Writer cannot be
queried for its encoding, the information must be passed to the Format
manually in its constructor or via the
method. The default encoding is
UTF-8.
Format#setEncoding
The methods are for
convenience only; for top performance you should call one of the outputString(. methods and pass in your own Writer or
OutputStream if possible.
output(.
XML declarations are always printed on their own line followed by a line
seperator (this doesn't change the semantics of the document). To omit
printing of the declaration use
. To omit printing of the
encoding in the declaration use Format#setOmitDeclaration.
Unfortunatly there is currently no way to know the original encoding of the
document.
Format#setOmitEncoding
Empty elements are by default printed as <empty/>, but this can be
configured with to cause
them to be expanded to <empty></empty>.
Format#setExpandEmptyElements
| Modifier and Type | Class and Description |
|---|---|
| protected class | XMLOutputter.NamespaceStack
Our own null subclass of NamespaceStack. |
| Modifier and Type | Field and Description |
|---|---|
| protected Format | |
| private static final String | |
| private boolean | escapeOutput
Whether output escaping is enabled for the being processed
Element - default is |
| protected static final Format | |
| private Format |
| Access | Constructor and Description |
|---|---|
| public | XMLOutputter()
This will create an |
| public | XMLOutputter(Format format)
This will create an |
| public | XMLOutputter(XMLOutputter
the XMLOutputter to clone that)This will create an |
| Modifier and Type | Method and Description |
|---|---|
| public Object | |
| private XMLOutputter. | |
| private boolean | |
| public String | Returns: String with escaped content.String input to escape.This will take the pre-defined entities in XML 1.0 and convert their character representation to the appropriate entity reference, suitable for XML attributes. |
| public String | Returns: String with escaped content.String input to escape.This will take the three pre-defined entities in XML 1.0 (used specifically in XML elements) and convert their character representation to the appropriate entity reference, suitable for XML element content. |
| public Format | |
| private void | |
| private boolean | |
| private Writer | makeWriter(OutputStream out)
Get an OutputStreamWriter, using prefered encoding
(see |
| private static Writer | |
| private void | |
| private static int | |
| public void | output(Document
Document to format.OutputStream to use.This will print the |
| public void | output(DocType
DocType to output.OutputStream to use.Print out the |
| public void | output(Element
Element to output.Writer to use.Print out an |
| public void | output(List<E>
List of nodes.OutputStream to use.This will handle printing out a list of nodes. |
| public void | |
| public void | |
| public void | |
| public void | output(ProcessingInstruction
ProcessingInstruction to output.OutputStream to use.Print out a |
| public void | output(EntityRef
EntityRef to output.OutputStream to use.Print out a |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | output(ProcessingInstruction
ProcessingInstruction to output.Writer to use.Print out a |
| public void | |
| public void | outputElementContent(Element
Element to output.OutputStream to use.This will handle printing out an |
| public void | outputElementContent(Element
Element to output.Writer to use.This will handle printing out an |
| public String | |
| public String | |
| public String | |
| public String | |
| public String | |
| public String | |
| public String | |
| public String | outputString(ProcessingInstruction
ProcessingInstruction to format.Return a string representing a PI. |
| public String | |
| private void | |
| protected void | printAttributes(Writer
Writer to useList of Attribute objctsThis will handle printing of a |
| protected void | printCDATA(Writer
Writer to use.CDATA to output.This will handle printing of |
| protected void | printComment(Writer
Writer to use.Comment to write.This will handle printing of comments. |
| private void | printContentRange(Writer
Writer to use.List of content to outputindex of first content node (inclusive. start, int index of last content node (exclusive). end, int int level of indentation.List stack of Namespaces in scope.This will handle printing of content within a given range. |
| protected void | printDeclaration(Writer
Writer to use.Document whose declaration to write.The encoding to add to the declaration encoding)This will handle printing of the declaration. |
| protected void | printDocType(Writer
Writer to use.Document whose declaration to write.This handle printing the DOCTYPE declaration if one exists. |
| protected void | printElement(Writer
Writer to use.Element to output.int level of indention.List stack of Namespaces in scope.This will handle printing of a |
| private void | |
| protected void | printEntityRef(Writer
Writer to use.EntityRef to output.This will handle printing a |
| private void | printNamespace(Writer
Writer to use.Namespace to print definition ofThis will handle printing of any needed |
| protected void | printProcessingInstruction(Writer
Writer to use.ProcessingInstruction to write.This will handle printing of processing instructions. |
| private void | |
| private void | |
| private void | |
| protected void | |
| private void | printTextRange(Writer
Writer to use.List of content to outputindex of first content node (inclusive). start, int index of last content node (exclusive). end)This will handle printing of a sequence of |
| public void | |
| private int | |
| private int | |
| private boolean | |
| public String | Returns: a string listing the settings for this XMLOutputter instanceOverrides java. |