XMLWriter takes a DOM4J tree and formats it to a stream as
XML. It can also take SAX events too so can be used by SAX clients as this
object implements the org.and LexicalHandler interfaces. as well. This formatter performs typical document
formatting. The XML declaration and processing instructions are always on
their own lines. An OutputFormatobject can be used to define how
whitespace is handled when printing and allows various configuration options,
such as to allow suppression of the XML declaration, the encoding declaration
or whether empty documents are collapsed.
There are write(...) methods to print any of the standard
DOM4J classes, including Document and Element,
to either a Writer or an OutputStream.
Warning
using your own Writer may cause the writer's
preferred character encoding to be ignored. If you use encodings other than
UTF8, we recommend using the method that takes an OutputStream instead.
| Modifier and Type | Field and Description |
|---|---|
| private boolean | autoFlush
Whether a flush should occur after writing a document |
| private StringBuffer | buffer
buffer used when escaping strings |
| private boolean | charsAdded
whether we have added characters before from the same chunk of characters |
| protected static final OutputFormat | |
| private boolean | escapeText
whether we should escape text |
| private OutputFormat | format
The format used by this writer |
| private int | indentLevel
The initial number of indentations (so you can print a whole document indented, if you like) |
| private boolean | inDTD
Is the writer curerntly inside a DTD definition? |
| private char | |
| private boolean | lastElementClosed
Stores if the last written element node was a closing tag or an opening tag. |
| protected int | lastOutputNodeType
Stores the last type of node written so algorithms can refer to the previous node type |
| protected static final String[] | |
| private LexicalHandler | lexicalHandler
Lexical handler we should delegate to |
| private int | maximumAllowedCharacter
what is the maximum allowed character code such as 127 in US-ASCII (7 bit) or 255 in ISO- (8 bit) or -1 to not escape any characters (other than the special XML characters like < > &) |
| private Map | namespacesMap
The namespaces used for the current element when consuming SAX events |
| private NamespaceStack | namespaceStack
The Stack of namespaceStack written so far |
| private static final String | |
| protected boolean | preserve
Stores the xml:space attribute value of preserve for whitespace flag |
| private boolean | resolveEntityRefs
Should entityRefs by resolved when writing ? |
| private boolean | showCommentsInDTDs
Whether comments should appear inside DTD declarations - defaults to false |
| protected Writer | writer
The Writer used to output to |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | characters(char[]
An array of characters. ch, int The starting position in the array. start, int The number of characters to use from the array. length)Overrides org. Implements org. |
| public void | |
| public void | comment(char[]
An array holding the characters in the comment. ch, int The starting position in the array. start, int The number of characters to use from the array. length)Implements org. |
| protected Writer | Returns: DOCUMENT ME!DOCUMENT ME! outStream, String DOCUMENT ME! encoding)Get an OutputStreamWriter, use preferred encoding. |
| protected int | Returns: DOCUMENT ME!Returns the maximum allowed character code that should be allowed unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8 bit). |
| public void | |
| public void | endDocument()
Overrides org. Implements org. |
| public void | |
| public void | endElement(String
The element's Namespace URI, or the empty string. namespaceURI, String The element's local name, or the empty string. localName, String The element's qualified (prefixed) name, or the empty
string. qName)Overrides org. Implements org. |
| public void | endEntity(String
The name of the entity that is ending. name)Implements org. |
| public void | endPrefixMapping(String
The Namespace prefix. prefix)Overrides org. Implements org. |
| protected String | Returns: DOCUMENT ME!DOCUMENT ME! text)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. |
| protected String | Returns: DOCUMENT ME!DOCUMENT ME! text)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 void | |
| public LexicalHandler | |
| public int | Returns: DOCUMENT ME!Returns the maximum allowed character code that should be allowed unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8 bit). |
| protected OutputFormat | Returns: DOCUMENT ME!Lets subclasses get at the current format object, so they can call setTrimText, setNewLines, etc. Put in to support the HTMLWriter, in the way that it pushes the current newline/trim state onto a stack and overrides the state within preformatted tags. |
| public Object | getProperty(String
The property name. name)Overrides org. Implements org. |
| protected void | |
| public void | ignorableWhitespace(char[]
An array of characters. ch, int The starting position in the array. start, int The number of characters to use from the array. length)Overrides org. Implements org. |
| protected void | |
| protected void | |
| protected final boolean | Returns: DOCUMENT ME!DOCUMENT ME! element)Determines if element is a special case of XML elements where it contains an xml:space attribute of "preserve". |
| public boolean | Returns: true if text thats output should be escaped. This is enabled by default. It could be disabled if the output format is textual, like in XSLT where we can have xml, html or text output.DOCUMENT ME! |
| protected boolean | |
| protected boolean | |
| public void | notationDecl(String
The notation name. name, String The notation's public identifier, or null. publicID, String The notation's system identifier, or null. systemID)Overrides org. Implements org. |
| public void | parse(InputSource
The input source for the document entity. source)Overrides org. Implements org. |
| public void | |
| public void | processingInstruction(String
The processing instruction target. target, String The text following the target. data)Overrides org. Implements org. |
| public boolean | |
| public void | setDocumentLocator(Locator
The document locator. locator)Overrides org. Implements org. |
| public void | |
| public void | setIndentLevel(int
the number of indents to start with indentLevel)Set the initial indentation level. |
| public void | |
| public void | setMaximumAllowedCharacter(int
The maximumAllowedCharacter to set maximumAllowedCharacter)Sets the maximum allowed character code that should be allowed unescaped such as 127 in US-ASCII (7 bit) or 255 in ISO- (8 bit) or -1 to not escape any characters (other than the special XML characters like < > &) If this is not explicitly set then it is defaulted from the encoding. |
| public void | |
| public void | setProperty(String
The property name. name, Object The requested property value. value)Overrides org. Implements org. |
| public void | |
| public void | |
| protected boolean | Returns: booleanUnicode codepoint.
DOCUMENT ME! codepoint)Should the given character be escaped. |
| public void | startCDATA()
Implements org. |
| public void | startDocument()
Overrides org. Implements org. |
| public void | startDTD(String
The document type name. name, String The declared public identifier for the
external DTD subset, or null if none was declared. publicID, String The declared system identifier for the
external DTD subset, or null if none was declared.
(Note that this is not resolved against the document
base URI.) systemID)Implements org. |
| public void | startElement(String
The element's Namespace URI, or the empty string. namespaceURI, String The element's local name, or the empty string. localName, String The element's qualified (prefixed) name, or the empty
string. qName, Attributes The element's attributes. attributes)Overrides org. Implements org. |
| public void | startEntity(String
The name of the entity. If it is a parameter
entity, the name will begin with '%', and if it is the
external DTD subset, it will be "[dtd]". name)Implements org. |
| public void | startPrefixMapping(String
The Namespace prefix. prefix, String The Namespace URI. uri)Overrides org. Implements org. |
| public void | unparsedEntityDecl(String
The entity name. name, String The entity's public identifier, or null. publicID, String The entity's system identifier, or null. systemID, String The name of the associated notation. notationName)Overrides org. Implements org. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | write(ProcessingInstruction
ProcessingInstruction to output.Writes the given |
| public void | |
| public void | |
| public void | |
| public void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| public void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | writeNodeText(Node
DOCUMENT ME! node)This method is used to write out Nodes that contain text and still allow for xml:space to be handled properly. |
| public void | |
| protected void | |
| protected void | |
| protected void |