org.dom4j.io
public class OutputFormat extends Object implements Cloneable
OutputFormat
represents the format configuration used by
{@linkXMLWriter }and its base classes to format the XML output
Version: $Revision: 1.17 $
Field Summary | |
---|---|
protected static String | STANDARD_INDENT standard value to indent by, if we are indenting |
Constructor Summary | |
---|---|
OutputFormat()
Creates an OutputFormat with no additional whitespace
(indent or new lines) added. | |
OutputFormat(String indent)
Creates an OutputFormat with the given indent added but no
new lines added. | |
OutputFormat(String indent, boolean newlines)
Creates an OutputFormat with the given indent added with
optional newlines between the Elements. | |
OutputFormat(String indent, boolean newlines, String encoding)
Creates an OutputFormat with the given indent added with
optional newlines between the Elements and the given encoding format.
|
Method Summary | |
---|---|
static OutputFormat | createCompactFormat()
A static helper method to create the default compact format. |
static OutputFormat | createPrettyPrint()
A static helper method to create the default pretty printing format. |
char | getAttributeQuoteCharacter() |
String | getEncoding() |
String | getIndent() |
String | getLineSeparator() |
int | getNewLineAfterNTags() |
boolean | isExpandEmptyElements() |
boolean | isNewlines() |
boolean | isNewLineAfterDeclaration()
DOCUMENT ME!
|
boolean | isOmitEncoding() |
boolean | isPadText() |
boolean | isSuppressDeclaration()
DOCUMENT ME!
|
boolean | isTrimText() |
boolean | isXHTML() Whether or not to use the XHTML standard: like HTML but passes an XML parser with real, closed tags. |
int | parseOptions(String[] args, int i)
Parses command line arguments of the form -omitEncoding
-indentSize 3 -newlines -trimText
|
void | setAttributeQuoteCharacter(char quoteChar)
Sets the character used to quote attribute values. |
void | setEncoding(String encoding)
DOCUMENT ME!
|
void | setExpandEmptyElements(boolean expandEmptyElements)
This will set whether empty elements are expanded from
|
void | setIndent(String indent)
This will set the indent |
void | setIndent(boolean doIndent)
Set the indent on or off. |
void | setIndentSize(int indentSize)
This will set the indent |
void | setLineSeparator(String separator) This will set the new-line separator. |
void | setNewlines(boolean newlines)
DOCUMENT ME!
|
void | setNewLineAfterDeclaration(boolean newLineAfterDeclaration) This will set whether a new line is printed after the XML declaration (assuming it is not supressed.) |
void | setNewLineAfterNTags(int tagCount)
Controls output of a line.separator every tagCount tags when isNewlines
is false. |
void | setOmitEncoding(boolean omitEncoding)
This will set whether the XML declaration ( |
void | setPadText(boolean padText) Ensure that text immediately preceded by or followed by an element will be "padded" with a single space. |
void | setSuppressDeclaration(boolean suppressDeclaration)
This will set whether the XML declaration ( |
void | setTrimText(boolean trimText)
This will set whether the text is output verbatim (false) or with
whitespace stripped as per |
void | setXHTML(boolean xhtml) This will set whether or not to use the XHTML standard: like HTML but passes an XML parser with real, closed tags. |
OutputFormat
with no additional whitespace
(indent or new lines) added. The whitespace from the element text content
is fully preserved.OutputFormat
with the given indent added but no
new lines added. All whitespace from element text will be included.
Parameters: indent is the indent string to be used for indentation (usually a number of spaces).
OutputFormat
with the given indent added with
optional newlines between the Elements. All whitespace from element text
will be included.
Parameters: indent is the indent string to be used for indentation (usually a number of spaces). newlines whether new lines are added to layout the
OutputFormat
with the given indent added with
optional newlines between the Elements and the given encoding format.
Parameters: indent is the indent string to be used for indentation (usually a number of spaces). newlines whether new lines are added to layout the encoding is the text encoding to use for writing the XML
Returns: DOCUMENT ME!
Returns: DOCUMENT ME!
Returns: true if a new line should be printed following XML declaration
Returns: true if the output of the XML declaration (<?xml
version="1.0"?>
)
should be suppressed else false.
Whether or not to use the XHTML standard: like HTML but passes an XML parser with real, closed tags. Also, XHTML CDATA sections will be output with the CDATA delimiters: ( " <![CDATA[ " and " ]]> " ) otherwise, the class HTMLWriter will output the CDATA text, but not the delimiters.
Default is false
Returns: DOCUMENT ME!
-omitEncoding
-indentSize 3 -newlines -trimText
Parameters: args is the array of command line arguments i is the index in args to start parsing options
Returns: the index of first parameter that we didn't understand
IllegalArgumentException
will be thrown.
Parameters: quoteChar The character to use when quoting attribute values.
Throws: IllegalArgumentException If the specified character is not a valid XML attribute quote character.
Parameters: encoding encoding format
This will set whether empty elements are expanded from
<tagName>
to
<tagName></tagName>
.
Parameters: expandEmptyElements
boolean
indicating whether or not empty
elements should be expanded.
This will set the indent String
to use; this is usually a
String
of empty spaces. If you pass null, or the empty
string (""), then no indentation will happen.
Parameters: indent
String
to use for indentation.
Parameters: doIndent if true, set indenting on; if false, set indenting off
This will set the indent String
's size; an indentSize of
4 would result in the indention being equivalent to the
String
" " (four space characters).
Parameters: indentSize
int
number of spaces in indentation.
This will set the new-line separator. The default is \n
.
Note that if the "newlines" property is false, this value is irrelevant.
To make it output the system default line ending string, call
setLineSeparator(System.getProperty("line.separator"))
Parameters: separator
String
line separator to use.
See Also: OutputFormat
Parameters: newlines
true
indicates new lines should be printed,
else new lines are ignored (compacted).
See Also: setLineSeparator
This will set whether a new line is printed after the XML declaration (assuming it is not supressed.)
Parameters: newLineAfterDeclaration
boolean
indicating whether or not to print new
line following the XML declaration. The default is true.
Parameters: tagCount DOCUMENT ME!
This will set whether the XML declaration (<?xml version="1.0"
encoding="UTF-8"?>
)
includes the encoding of the document. It is common to suppress this in
protocols such as WML and SOAP.
Parameters: omitEncoding
boolean
indicating whether or not the XML
declaration should indicate the document encoding.
Ensure that text immediately preceded by or followed by an element will
be "padded" with a single space. This is used to allow make
browser-friendly HTML, avoiding trimText's transformation of, e.g.,
The quick <b>brown</b> fox
into The
quick<b>brown</b>fox
(the latter will run the three separate words together into a single
word). This setting is not too useful if you haven't also called
OutputFormat.
The padding string will only be added if the text itself starts or ends with some whitespace characters.
Default: false
Parameters: padText
boolean
if true, pad string-element boundaries
This will set whether the XML declaration (<?xml version="1.0"
encoding="UTF-8"?>
)
is included or not. It is common to suppress this in protocols such as
WML and SOAP.
Parameters: suppressDeclaration
boolean
indicating whether or not the XML
declaration should be suppressed.
This will set whether the text is output verbatim (false) or with
whitespace stripped as per getTextTrim
.
Default: false
Parameters: trimText
boolean
true=>trim the whitespace, false=>use
text verbatim
This will set whether or not to use the XHTML standard: like HTML but passes an XML parser with real, closed tags. Also, XHTML CDATA sections will be output with the CDATA delimiters: ( " <[CDATA[ " and " ]]< ) otherwise, the class HTMLWriter will output the CDATA text, but not the delimiters.
Default: false
Parameters: xhtml
boolean
true=>conform to XHTML, false=>conform
to HTML, can have unclosed tags, etc.