getRawFormat (no whitespace changes),
getPrettyFormat (whitespace beautification), and
getCompactFormat (whitespace normalization).
Several modes are available to effect the way textual content is printed.
See the documentation for TextMode for details.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class | Format.DefaultEscapeStrategy
Handle common charsets quickly and easily. |
| public static class | Format.TextMode
Class to signify how text should be handled on output. |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| pack-priv String | encoding
The encoding format |
| pack-priv EscapeStrategy | escapeStrategy
entity escape logic |
| pack-priv boolean | expandEmptyElements
Whether or not to expand empty elements to
<tagName></tagName> - default is |
| pack-priv boolean | ignoreTrAXEscapingPIs
Whether TrAX output escaping disabling/enabling PIs are ignored
or processed - default is |
| pack-priv String | indent
The default indent is no spaces (as original document) |
| pack-priv String | lineSeparator
New line separator |
| pack-priv Format. | mode
text handling mode |
| pack-priv boolean | omitDeclaration
Whether or not to output the XML declaration
- default is |
| pack-priv boolean | omitEncoding
Whether or not to output the encoding in the XML declaration
- default is |
| private static final String | STANDARD_ENCODING
standard encoding |
| private static final String | STANDARD_INDENT
standard value to indent by, if we are indenting |
| private static final String | STANDARD_LINE_SEPARATOR
standard string with which to end a line |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Object | |
| public static Format | Returns: a Format with whitespace normalizationReturns a new Format object that performs whitespace normalization, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy. |
| public String | |
| public EscapeStrategy | |
| public boolean | Returns: whether empty elements are expandedReturns whether empty elements are expanded. |
| public boolean | Returns: whether or not TrAX ouput escaping PIs are ignored.Returns whether JAXP TrAX processing instructions for disabling/enabling output escaping are ignored. |
| public String | |
| public String | |
| public boolean | Returns: whether the XML declaration will be omittedReturns whether the XML declaration will be omitted. |
| public boolean | Returns: whether the XML declaration encoding will be omittedReturns whether the XML declaration encoding will be omitted. |
| public static Format | Returns: a Format with whitespace beautificationReturns a new Format object that performs whitespace beautification with 2-space indents, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy. |
| public static Format | Returns: a Format with no whitespace changesReturns a new Format object that performs no whitespace changes, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy. |
| public Format. | |
| public Format | Returns: a pointer to this Format for chainingthe encoding format. Use XML-style names like
"UTF-8" or "ISO-8859-1" or "US-ASCII" encoding)Sets the output encoding. |
| public Format | Returns: a pointer to this Format for chainingthe EscapeStrategy to use strategy)Sets the |
| public Format | Returns: a pointer to this Format for chainingboolean indicating whether or not
empty elements should be expanded.This will set whether empty elements are expanded from
|
| public void | setIgnoreTrAXEscapingPIs(boolean
boolean indicating
whether or not TrAX ouput escaping PIs are ignored.This will set whether JAXP TrAX processing instructions for disabling/enabling output escaping are ignored. |
| public Format | |
| public Format | Returns: a pointer to this Format for chainingString line separator to use.This will set the newline separator ( |
| public Format | Returns: a pointer to this Format for chainingboolean indicating whether or not
the XML declaration should be omitted.This will set whether the XML declaration
( |
| public Format | Returns: a pointer to this Format for chainingboolean indicating whether or not
the XML declaration should indicate the document encoding.This will set whether the XML declaration
( |
| public Format | Returns: a pointer to this Format for chainingThis sets the text output style. |
| CVS_ID | back to summary |
|---|---|
| private static final String CVS_ID | |
| encoding | back to summary |
|---|---|
| pack-priv String encoding The encoding format | |
| escapeStrategy | back to summary |
|---|---|
| pack-priv EscapeStrategy escapeStrategy entity escape logic | |
| expandEmptyElements | back to summary |
|---|---|
| pack-priv boolean expandEmptyElements Whether or not to expand empty elements to
<tagName></tagName> - default is | |
| ignoreTrAXEscapingPIs | back to summary |
|---|---|
| pack-priv boolean ignoreTrAXEscapingPIs Whether TrAX output escaping disabling/enabling PIs are ignored
or processed - default is | |
| indent | back to summary |
|---|---|
| pack-priv String indent The default indent is no spaces (as original document) | |
| lineSeparator | back to summary |
|---|---|
| pack-priv String lineSeparator New line separator | |
| mode | back to summary |
|---|---|
| pack-priv Format. text handling mode | |
| omitDeclaration | back to summary |
|---|---|
| pack-priv boolean omitDeclaration Whether or not to output the XML declaration
- default is | |
| omitEncoding | back to summary |
|---|---|
| pack-priv boolean omitEncoding Whether or not to output the encoding in the XML declaration
- default is | |
| STANDARD_ENCODING | back to summary |
|---|---|
| private static final String STANDARD_ENCODING standard encoding | |
| STANDARD_INDENT | back to summary |
|---|---|
| private static final String STANDARD_INDENT standard value to indent by, if we are indenting | |
| STANDARD_LINE_SEPARATOR | back to summary |
|---|---|
| private static final String STANDARD_LINE_SEPARATOR standard string with which to end a line | |
| Format | back to summary |
|---|---|
| private Format() Creates a new Format instance with default (raw) behavior. | |
| clone | back to summary |
|---|---|
| public Object clone() Overrides java. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by
| |
| getCompactFormat | back to summary |
|---|---|
| public static Format getCompactFormat() Returns a new Format object that performs whitespace normalization, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy. Tweaks can be made to the returned Format instance without affecting other instances.
| |
| getEncoding | back to summary |
|---|---|
| public String getEncoding() Returns the configured output encoding.
| |
| getEscapeStrategy | back to summary |
|---|---|
| public EscapeStrategy getEscapeStrategy() Returns the current escape strategy
| |
| getExpandEmptyElements | back to summary |
|---|---|
| public boolean getExpandEmptyElements() Returns whether empty elements are expanded.
| |
| getIgnoreTrAXEscapingPIs | back to summary |
|---|---|
| public boolean getIgnoreTrAXEscapingPIs() Returns whether JAXP TrAX processing instructions for disabling/enabling output escaping are ignored.
| |
| getIndent | back to summary |
|---|---|
| public String getIndent() Returns the indent string in use.
| |
| getLineSeparator | back to summary |
|---|---|
| public String getLineSeparator() Returns the current line separator.
| |
| getOmitDeclaration | back to summary |
|---|---|
| public boolean getOmitDeclaration() Returns whether the XML declaration will be omitted.
| |
| getOmitEncoding | back to summary |
|---|---|
| public boolean getOmitEncoding() Returns whether the XML declaration encoding will be omitted.
| |
| getPrettyFormat | back to summary |
|---|---|
| public static Format getPrettyFormat() Returns a new Format object that performs whitespace beautification with 2-space indents, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy. Tweaks can be made to the returned Format instance without affecting other instances.
| |
| getRawFormat | back to summary |
|---|---|
| public static Format getRawFormat() Returns a new Format object that performs no whitespace changes, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy. Tweaks can be made to the returned Format instance without affecting other instances.
| |
| getTextMode | back to summary |
|---|---|
| public Format. Returns the current text output style. | |
| setEncoding | back to summary |
|---|---|
| public Format setEncoding(String encoding) Sets the output encoding. The name should be an accepted XML encoding. | |
| setEscapeStrategy | back to summary |
|---|---|
| public Format setEscapeStrategy(EscapeStrategy strategy) Sets the
| |
| setExpandEmptyElements | back to summary |
|---|---|
| public Format setExpandEmptyElements(boolean expandEmptyElements) This will set whether empty elements are expanded from
| |
| setIgnoreTrAXEscapingPIs | back to summary |
|---|---|
| public void setIgnoreTrAXEscapingPIs(boolean ignoreTrAXEscapingPIs) This will set whether JAXP TrAX processing instructions for disabling/enabling output escaping are ignored. Disabling output escaping allows using XML text as element content and outputing it verbatim, i.e. as element children would be.
When processed, these processing instructions are removed from
the generated XML text and control whether the element text
content is output verbatim or with escaping of the pre-defined
entities in XML 1.0. The text to be output verbatim shall be
surrounded by the
When ignored, the processing instructions are present in the generated XML text and the pre-defined entities in XML 1.0 are escaped.
Default:
| |
| setIndent | back to summary |
|---|---|
| public Format setIndent(String indent) This will set the indent | |
| setLineSeparator | back to summary |
|---|---|
| public Format setLineSeparator(String separator) This will set the newline separator (
To output "UNIX-style" documents, call
Note that this only applies to newlines generated by the outputter. If you parse an XML document that contains newlines embedded inside a text node, and you do not set TextMode.NORMALIZE, then the newlines will be output verbatim, as "\n" which is how parsers normalize them. If the format's "indent" property is null (as is the default for the Raw and Compact formats), then this value only effects the newlines written after the declaration and doctype.
| |
| setOmitDeclaration | back to summary |
|---|---|
| public Format setOmitDeclaration(boolean omitDeclaration) This will set whether the XML declaration
(
| |
| setOmitEncoding | back to summary |
|---|---|
| public Format setOmitEncoding(boolean omitEncoding) This will set whether the XML declaration
(
| |
| setTextMode | back to summary |
|---|---|
| public Format setTextMode(Format. This sets the text output style. Options are available as static
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | shouldEscape(char ch)
Implements org. |
| bits | back to summary |
|---|---|
| private int bits | |
| canEncode | back to summary |
|---|---|
| pack-priv Method canEncode | |
| encoder | back to summary |
|---|---|
| pack-priv Object encoder | |
| DefaultEscapeStrategy | back to summary |
|---|---|
| public DefaultEscapeStrategy(String encoding) | |
| shouldEscape | back to summary |
|---|---|
| public boolean shouldEscape(char ch) Implements org. Doc from org. Test whether the supplied character should be formatted literally or as a character entity. | |
| Text Mode | Resulting behavior. |
|---|---|
| PRESERVE (Default) | All content is printed in the format it was created, no whitespace or line separators are are added or removed. |
| TRIM_FULL_WHITE | Content between tags consisting of all whitespace is not printed. If the content contains even one non-whitespace character, it is printed verbatim, whitespace and all. |
| TRIM | Same as TrimAllWhite, plus leading/trailing whitespace are trimmed. |
| NORMALIZE | Same as TextTrim, plus addition interior whitespace is compressed to a single space. |
When a element has a xml:space attribute with the value of "preserve", all formating is turned off and reverts back to the default until the element and its contents have been printed. If a nested element contains another xml:space with the value "default" formatting is turned back on for the child element and then off for the remainder of the parent element.
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| public static final Format. | NORMALIZE
Mode for text normalization (left and right trim plus internal whitespace is normalized to a single space. |
| public static final Format. | PRESERVE
Mode for literal text preservation. |
| public static final Format. | TRIM
Mode for text trimming (left and right trim). |
| public static final Format. | TRIM_FULL_WHITE
Mode for text trimming of content consisting of nothing but whitespace but otherwise not changing output. |
| Modifier and Type | Method and Description |
|---|---|
| public String |
| name | back to summary |
|---|---|
| private final String name | |
| NORMALIZE | back to summary |
|---|---|
| public static final Format. Mode for text normalization (left and right trim plus internal whitespace is normalized to a single space.
| |
| PRESERVE | back to summary |
|---|---|
| public static final Format. Mode for literal text preservation. | |
| TRIM | back to summary |
|---|---|
| public static final Format. Mode for text trimming (left and right trim). | |
| TRIM_FULL_WHITE | back to summary |
|---|---|
| public static final Format. Mode for text trimming of content consisting of nothing but whitespace but otherwise not changing output. | |
| TextMode | back to summary |
|---|---|
| private TextMode(String name) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
| |