public class XmlWriter
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CDATA_END
CDATA end tag: "]]>"
|
static java.lang.String |
CDATA_START
CDATA start tag: "
|
static java.nio.charset.Charset |
DEFAULT_CHARSET |
static java.lang.String |
DEFAULT_ENCODING
Default encoding value which is "UTF-8"
|
Constructor and Description |
---|
XmlWriter(java.io.OutputStream outputStream,
java.nio.charset.Charset charset)
Create an XmlWriter on top of an existing
OutputStream . |
XmlWriter(java.io.Writer writer)
Create an XmlWriter on top of an existing java.io.Writer.
|
XmlWriter(java.io.Writer writer,
java.nio.charset.Charset charset)
Create an XmlWriter on top of an existing java.io.Writer.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this writer.
|
protected java.lang.String |
convertCharacterToEntity(char currentChar,
boolean literally) |
void |
enablePrettyPrint(boolean enable)
Turn pretty printing on or off.
|
XmlWriter |
endElement()
End the current element.
|
static void |
main(java.lang.String[] args) |
void |
setIndent(java.lang.String indent)
Specify the string to prepend to a line for each level of indent.
|
void |
setNewline(java.lang.String newline)
Specify the string used to terminate each line when pretty printing.
|
void |
setWriter(java.io.Writer writer,
java.nio.charset.Charset charset) |
void |
setWriter(java.io.Writer writer,
java.lang.String encoding)
Resets the handler to write a new text document.
|
static void |
test1() |
static void |
test2() |
XmlWriter |
writeAttribute(java.lang.String attr,
java.lang.String value)
Write an attribute out for the current element.
|
XmlWriter |
writeAttribute(java.lang.String attr,
java.lang.String value,
boolean literally)
Write an attribute out for the current element.
|
XmlWriter |
writeCData(java.lang.String cdata)
Write out a chunk of CDATA.
|
XmlWriter |
writeComment(java.lang.String comment)
Write out a chunk of comment.
|
XmlWriter |
writeDeclaration() |
XmlWriter |
writeDoctype(java.lang.String systemId,
java.lang.String publicId) |
XmlWriter |
writeElement(java.lang.String name)
Begin to write out an element.
|
XmlWriter |
writeElementWithText(java.lang.String name,
java.lang.String text)
A helper method.
|
XmlWriter |
writeEmptyElement(java.lang.String name)
A helper method.
|
XmlWriter |
writeText(java.lang.String text)
Output body text.
|
XmlWriter |
writeText(java.lang.String text,
boolean literally)
Output body text.
|
public static final java.lang.String CDATA_START
public static final java.lang.String CDATA_END
public static final java.lang.String DEFAULT_ENCODING
public static final java.nio.charset.Charset DEFAULT_CHARSET
public XmlWriter(java.io.Writer writer)
public XmlWriter(java.io.Writer writer, java.nio.charset.Charset charset)
public XmlWriter(java.io.OutputStream outputStream, java.nio.charset.Charset charset)
OutputStream
.outputStream
- charset
- The charset to be used for writing to the given output stream.
Can be null
. If it is null
the
DEFAULT_ENCODING
is used.public void enablePrettyPrint(boolean enable)
enable
- true to enable, false to disable pretty printing.public void setIndent(java.lang.String indent)
indent
- representing one level of indentation while pretty printing.public void setNewline(java.lang.String newline)
newline
- representing the newline sequence when pretty printing.public XmlWriter writeElementWithText(java.lang.String name, java.lang.String text) throws java.io.IOException
name
- String name of tagtext
- String of text to go inside the tagjava.io.IOException
public XmlWriter writeEmptyElement(java.lang.String name) throws java.io.IOException
name
- String name of tagjava.io.IOException
public XmlWriter writeElement(java.lang.String name) throws java.io.IOException
name
- String name of tagjava.io.IOException
public XmlWriter writeAttribute(java.lang.String attr, java.lang.String value) throws java.io.IOException
attr
- name of attribute.value
- value of attribute.java.io.IOException
writeAttribute(String, String, boolean)
public XmlWriter writeAttribute(java.lang.String attr, java.lang.String value, boolean literally) throws java.io.IOException
attr
- name of attribute.value
- value of attribute.literally
- If the writer should be literally on the given value which
means that meta characters will also be preserved by escaping
them. Mainly preserves newlines and tabs.java.io.IOException
public XmlWriter endElement() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException
public XmlWriter writeText(java.lang.String text) throws java.io.IOException
text
- The text to be writtenjava.io.IOException
writeText(String, boolean)
public XmlWriter writeText(java.lang.String text, boolean literally) throws java.io.IOException
text
- The text to be writtenliterally
- If the writer should be literally on the given value which
means that meta characters will also be preserved by escaping
them. Mainly preserves newlines and tabs.java.io.IOException
public XmlWriter writeCData(java.lang.String cdata) throws java.io.IOException
cdata
- of CDATA text.java.io.IOException
public XmlWriter writeComment(java.lang.String comment) throws java.io.IOException
comment
- of text to comment.java.io.IOException
public static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException
public static void test1() throws java.io.IOException
java.io.IOException
public static void test2() throws java.io.IOException
java.io.IOException
protected java.lang.String convertCharacterToEntity(char currentChar, boolean literally)
public final void setWriter(java.io.Writer writer, java.lang.String encoding)
writer
- XML text is written to this writer.encoding
- if non-null, and an XML declaration is written, this is the
name that will be used for the character encoding.java.lang.IllegalStateException
- if the current document hasn't yet ended (i.e. the output
stream out
is not null)public final void setWriter(java.io.Writer writer, java.nio.charset.Charset charset)
public XmlWriter writeDeclaration() throws java.io.IOException
java.io.IOException
public XmlWriter writeDoctype(java.lang.String systemId, java.lang.String publicId) throws java.io.IOException
java.io.IOException
Copyright © 2002-2025. All Rights Reserved.