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.lang.String |
DEFAULT_ENCODING
Default encoding value which is "UTF-8"
|
| Constructor and Description |
|---|
XmlWriter(java.io.OutputStream outputStream,
java.lang.String encoding)
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.lang.String encoding)
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.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 XmlWriter(java.io.Writer writer)
public XmlWriter(java.io.Writer writer,
java.lang.String encoding)
public XmlWriter(java.io.OutputStream outputStream,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException
OutputStream.outputStream - encoding - The encoding to be used for writing to the given output
stream. Can be null. If it is null
the DEFAULT_ENCODING is used.java.io.UnsupportedEncodingExceptionpublic 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.IOExceptionpublic XmlWriter writeEmptyElement(java.lang.String name) throws java.io.IOException
name - String name of tagjava.io.IOExceptionpublic XmlWriter writeElement(java.lang.String name) throws java.io.IOException
name - String name of tagjava.io.IOExceptionpublic XmlWriter writeAttribute(java.lang.String attr, java.lang.String value) throws java.io.IOException
attr - name of attribute.value - value of attribute.java.io.IOExceptionwriteAttribute(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.IOExceptionpublic XmlWriter endElement() throws java.io.IOException
java.io.IOExceptionpublic void close()
throws java.io.IOException
java.io.IOExceptionpublic XmlWriter writeText(java.lang.String text) throws java.io.IOException
text - The text to be writtenjava.io.IOExceptionwriteText(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.IOExceptionpublic XmlWriter writeCData(java.lang.String cdata) throws java.io.IOException
cdata - of CDATA text.java.io.IOExceptionpublic XmlWriter writeComment(java.lang.String comment) throws java.io.IOException
comment - of text to comment.java.io.IOExceptionpublic static void main(java.lang.String[] args)
throws java.io.IOException
java.io.IOExceptionpublic static void test1()
throws java.io.IOException
java.io.IOExceptionpublic static void test2()
throws java.io.IOException
java.io.IOExceptionprotected 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 XmlWriter writeDeclaration() throws java.io.IOException
java.io.IOExceptionpublic XmlWriter writeDoctype(java.lang.String systemId, java.lang.String publicId) throws java.io.IOException
java.io.IOExceptionCopyright © 2002-2018. All Rights Reserved.