public class XmlWriter extends Object
An XML writer knows hardly anything about XML document well-formedness, to say nothing of validity. It relies upon the invoker to ensure that the generated document is well-formed and, if required, valid.
Note: This class is incomplete. In the next draft it will be extended to more closely mimic the Xerces XMLScanner, and to support output to both SAX streams and DOM documents.
| Constructor and Description |
|---|
XmlWriter(OutputStream out)
Creates a new writer that will write to the given byte-output stream
using the UTF-8 encoding.
|
XmlWriter(OutputStream out,
String enc)
Creates a new writer that will write to the given byte-output stream
using the given encoding.
|
XmlWriter(OutputStream out,
String enc,
boolean declare)
Creates a new writer that will write to the given byte-output stream
using the given encoding.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attribute(String name,
String value)
Writes an attribute for the current element.
|
void |
attribute(String prefix,
String name,
String value)
Writes an attribute for the current element.
|
void |
attributeName(String name)
Writes an attribute name for the current element.
|
void |
attributeName(String prefix,
String name)
Writes an attribute name for the current element.
|
void |
attributeUnquoted(String name,
String value)
Writes an attribute (unquoted) for the current element.
|
void |
attributeUnquoted(String prefix,
String name,
String value)
Writes an attribute (unquoted) for the current element.
|
void |
attributeValue(String value)
Writes a value for the current attribute.
|
void |
attributeValueToken(String token)
Writes one token of the current attribute's value.
|
void |
attributeValueUnquoted(String value)
Writes a value (unquoted) for the current attribute.
|
void |
chars(CDATA chars) |
void |
chars(String chars)
Writes some character data.
|
void |
charsUnquoted(char[] buf,
int off,
int len)
Writes some character data, skipping quoting.
|
void |
charsUnquoted(String chars)
Writes some character data, skipping quoting.
|
void |
close()
Flushes the writer and closes the underlying byte-output stream.
|
void |
doctype(String root,
String dtd)
Writes a DOCTYPE declaration.
|
void |
end(String name)
Writes an end tag for the named element.
|
void |
flush()
Flushes the writer.
|
void |
inlineLeaf(String name) |
void |
inlineLeaf(String name,
String chars) |
void |
leaf(String name)
Writes an empty leaf element.
|
void |
leaf(String name,
String chars)
Writes a leaf element with the given character content.
|
void |
setQuote(char quote)
Sets the quote character to be used by this writer when writing
attribute values.
|
void |
start(String name)
Writes a start tag for the named element.
|
public XmlWriter(OutputStream out, String enc, boolean declare) throws UnsupportedEncodingException, IOException
out - The target byte-output streamenc - The character encoding to be useddeclare - If true, write the XML declaration to the output streamIOException - If an I/O error occursUnsupportedEncodingException - If the named encoding is not supportedpublic XmlWriter(OutputStream out, String enc) throws UnsupportedEncodingException, IOException
out - The target byte-output streamenc - The character encoding to be usedIOException - If an I/O error occursUnsupportedEncodingException - If the named encoding is not supportedpublic XmlWriter(OutputStream out) throws IOException
out - The target byte-output streamIOException - If an I/O error occurspublic void setQuote(char quote)
quote - The new quote character, either a
QUOTATION MARK ('\u0022'),
or an APOSTROPHE-QUOTE
('\u0027')IllegalArgumentException - If the argument is neither of the above characterspublic void doctype(String root, String dtd) throws IOException
root - The name of the root elementdtd - The URI of the document-type definitionIOException - If an I/O error occurspublic void start(String name) throws IOException
name - The name to be used in the start tagIOException - If an I/O error occurspublic void attribute(String name, String value) throws IOException
name - The attribute's namevalue - The attribute's valueIllegalStateException - If the previous method invoked upon this object was neither
start nor attributeIOException - If an I/O error occurspublic void attributeUnquoted(String name, String value) throws IOException
name - The attribute's namevalue - The attribute's valueIllegalStateException - If the previous method invoked upon this object was neither
start nor attributeIOException - If an I/O error occurspublic void attribute(String prefix, String name, String value) throws IOException
prefix - The attribute's prefixname - The attribute's namevalue - The attribute's valueIllegalStateException - If the previous method invoked upon this object was neither
start nor attributeIOException - If an I/O error occurspublic void attributeUnquoted(String prefix, String name, String value) throws IOException
prefix - The attribute's prefixname - The attribute's namevalue - The attribute's valueIllegalStateException - If the previous method invoked upon this object was neither
start nor attributeIOException - If an I/O error occurspublic void attributeName(String name) throws IOException
attributeValue method to
write the attribute value, or invoke the attributeValueToken method to write one or more space-separated value
tokens. name - The attribute's nameIllegalStateException - If the previous method invoked upon this object was neither
start nor attributeIOExceptionpublic void attributeName(String prefix, String name) throws IOException
attributeValue method to
write the attribute value, or invoke the attributeValueToken method to write one or more space-separated value
tokens. prefix - The attribute's prefixname - The attribute's nameIllegalStateException - If the previous method invoked upon this object was neither
start nor attributeIOExceptionpublic void attributeValue(String value) throws IOException
value - The attribute's valueIllegalStateException - If the previous method invoked upon this object was not
attributeNameIOExceptionpublic void attributeValueUnquoted(String value) throws IOException
value - The attribute's valueIllegalStateException - If the previous method invoked upon this object was not
attributeNameIOExceptionpublic void attributeValueToken(String token) throws IOException
token - The token to be writtenIllegalStateException - If the previous method invoked upon this object was neither
attributeName nor
attributeValueTokenIOExceptionpublic void end(String name) throws IOException
name - The name to be used in the end tagIOException - If an I/O error occurspublic void chars(String chars) throws IOException
chars - The character data to be writtenIOException - If an I/O error occurspublic void chars(CDATA chars) throws IOException
IOExceptionpublic void charsUnquoted(String chars) throws IOException
chars - The character data to be writtenIOException - If an I/O error occurspublic void charsUnquoted(char[] buf,
int off,
int len)
throws IOException
buf - Buffer containing the character data to be writtenoff - The offset of the data to be writtenlen - The length of the data to be writtenIOException - If an I/O error occurspublic void leaf(String name, String chars) throws IOException
name - The name to be used in the start and end tagschars - The character data to be written
This method writes a start tag with the given name, followed by the given character data, followed by an end tag. If the chars parameter is null or the empty string then an empty tag is written.
IOException - If an I/O error occurspublic void inlineLeaf(String name, String chars) throws IOException
IOExceptionpublic void leaf(String name) throws IOException
name - The name to be used in the empty-element tagIOExceptionpublic void inlineLeaf(String name) throws IOException
IOExceptionpublic void flush()
throws IOException
IOException - If an I/O error occurspublic void close()
throws IOException
IOException - If an I/O error occursCopyright © 2017–2019 Eclipse Foundation. All rights reserved.