public class XMLWriter extends Object
IMPORTANT: flush() or close() must always be called to assure all content is flushed to the underlying streams.
If a StringWriter is used the flush() or close() must be be called before calling the
toString() method
| Constructor and Description |
|---|
XMLWriter(String path)
Creates a new XML document on disk.
|
XMLWriter(Writer writer)
Creates a new XML document for a given writer object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
appendRawXML(String xmlData)
Writes a chunk of raw XML (and line-breaks are normalized to platform specific ones).
|
void |
close()
Closes the writer and release any associated resources.
|
protected void |
finalize() |
void |
flush()
Flushes the current buffer to the device.
|
String |
getLineBreak()
Gets the line break string currently used for this writer.
|
void |
setLineBreak(String lineBreak)
Sets the type of line-break to use when writing out the
document.
|
void |
writeAttributeString(String name,
String value)
Writes an attribute and its associated value.
|
void |
writeComment(String text,
boolean withLineBreak)
Writes a comment.
|
void |
writeElementString(String name,
String content)
Writes an element and its content.
|
void |
writeEndDocument()
Writes the end of the document.
|
void |
writeEndElement()
Writes the end of the last started element.
|
void |
writeEndElementLineBreak()
Writes the end of the last started element and writes a line-break.
|
void |
writeLineBreak()
Writes a line-break, and if the writer is in a start tag, close it before.
|
void |
writeRawXML(String xmlData)
Writes a chunk of raw XML (and line-breaks are normalized to platform specific ones).
|
void |
writeStartDocument()
Writes the start of the document.
|
void |
writeStartElement(String name)
Writes the start of an element.
|
void |
writeStartHTMLDocument(String title)
Writes the start of a XHTML document, including the head and start of body element.
|
void |
writeString(String text)
Writes a string.
|
public XMLWriter(String path)
path - the full path of the document to create. If any directory in the
path does not exists yet it will be created automatically. The document is
always written in UTF-8 and the type of line-breaks is the one of the
platform where the application runs.public XMLWriter(Writer writer)
writer - the writer to use to output the document. If this writer outputs to
bytes it must be set to output in UTF-8.protected void finalize()
throws Throwable
public void setLineBreak(String lineBreak)
lineBreak - the new type of line-break to use.public String getLineBreak()
public void close()
public void writeStartDocument()
public void writeStartHTMLDocument(String title)
title - the title of the document (can be null).public void writeEndDocument()
public void writeStartElement(String name)
name - the name of the element to start.public void writeEndElement()
public void writeEndElementLineBreak()
public void writeElementString(String name, String content)
name - the name of the element to write.content - the content to enclose inside this element.public void writeAttributeString(String name, String value)
writeStartElement(String) just before.name - the name of the attribute.value - the value of the attribute.public void writeString(String text)
text - the text to output.public void writeRawXML(String xmlData)
appendRawXML(String) to output without preliminary closing.xmlData - the data to output. No escaping is performed, but the line-breaks are
converted to the line-break type of the output.public void appendRawXML(String xmlData)
xmlData - the data to output. No escaping is performed, but the line-breaks are
converted to the line-break type of the output.public void writeComment(String text, boolean withLineBreak)
text - the text of the comment.withLineBreak - add a line break at the end of the comment.public void writeLineBreak()
public void flush()
Copyright © 2021. All rights reserved.