Package com.sun.xml.rpc.util.xml
Class PrettyPrintingXmlWriter
java.lang.Object
com.sun.xml.rpc.util.xml.PrettyPrintingXmlWriter
A writer of XML output streams.
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.
- Author:
- JAX-RPC Development Team
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new writer that will write to the given byte-output stream using the UTF-8 encoding.PrettyPrintingXmlWriter(OutputStream out, String enc) Creates a new writer that will write to the given byte-output stream using the given encoding.PrettyPrintingXmlWriter(OutputStream out, String enc, boolean declare) Creates a new writer that will write to the given byte-output stream using the given encoding. -
Method Summary
Modifier and TypeMethodDescriptionvoidWrites an attribute for the current element.voidWrites an attribute for the current element.voidattributeName(String name) Writes an attribute name for the current element.voidattributeName(String prefix, String name) Writes an attribute name for the current element.voidattributeUnquoted(String name, String value) Writes an attribute (unquoted) for the current element.voidattributeUnquoted(String prefix, String name, String value) Writes an attribute (unquoted) for the current element.voidattributeValue(String value) Writes a value for the current attribute.voidattributeValueToken(String token) Writes one token of the current attribute's value.voidattributeValueUnquoted(String value) Writes a value (unquoted) for the current attribute.voidvoidWrites some character data.voidcharsUnquoted(char[] cbuf, int off, int len) Writes some character data, skipping quoting.voidcharsUnquoted(String chars) Writes some character data, skipping quoting.voidclose()Flushes the writer and closes the underlying byte-output stream.voidWrites a DOCTYPE declaration.voidWrites an end tag for the named element.voidflush()Flushes the writer.voidinlineLeaf(String name) voidinlineLeaf(String name, String chars) voidWrites an empty leaf element.voidWrites a leaf element with the given character content.voidsetQuote(char quote) Sets the quote character to be used by this writer when writing attribute values.voidWrites a start tag for the named element.
-
Constructor Details
-
PrettyPrintingXmlWriter
public PrettyPrintingXmlWriter(OutputStream out, String enc, boolean declare) throws UnsupportedEncodingException, IOException Creates a new writer that will write to the given byte-output stream using the given encoding. An initial XML declaration will optionally be written to the stream.- Parameters:
out- The target byte-output streamenc- The character encoding to be useddeclare- If true, write the XML declaration to the output stream- Throws:
IOException- If an I/O error occursUnsupportedEncodingException- If the named encoding is not supported
-
PrettyPrintingXmlWriter
public PrettyPrintingXmlWriter(OutputStream out, String enc) throws UnsupportedEncodingException, IOException Creates a new writer that will write to the given byte-output stream using the given encoding. An initial XML declaration will be written to the stream.- Parameters:
out- The target byte-output streamenc- The character encoding to be used- Throws:
IOException- If an I/O error occursUnsupportedEncodingException- If the named encoding is not supported
-
PrettyPrintingXmlWriter
Creates a new writer that will write to the given byte-output stream using the UTF-8 encoding. An initial XML declaration will be written to the stream.- Parameters:
out- The target byte-output stream- Throws:
IOException- If an I/O error occurs
-
-
Method Details
-
setQuote
public void setQuote(char quote) Sets the quote character to be used by this writer when writing attribute values.- Parameters:
quote- The new quote character, either a QUOTATION MARK ('\u0022'), or an APOSTROPHE-QUOTE ('\u0027')- Throws:
IllegalArgumentException- If the argument is neither of the above characters
-
doctype
Writes a DOCTYPE declaration.- Parameters:
root- The name of the root elementdtd- The URI of the document-type definition- Throws:
IOException- If an I/O error occurs
-
start
Writes a start tag for the named element.- Parameters:
name- The name to be used in the start tag- Throws:
IOException- If an I/O error occurs
-
attribute
Writes an attribute for the current element.- Parameters:
name- The attribute's namevalue- The attribute's value- Throws:
IllegalStateException- If the previous method invoked upon this object was neitherstartnorattributeIOException- If an I/O error occurs
-
attributeUnquoted
Writes an attribute (unquoted) for the current element.- Parameters:
name- The attribute's namevalue- The attribute's value- Throws:
IllegalStateException- If the previous method invoked upon this object was neitherstartnorattributeIOException- If an I/O error occurs
-
attribute
Writes an attribute for the current element.- Parameters:
prefix- The attribute's prefixname- The attribute's namevalue- The attribute's value- Throws:
IllegalStateException- If the previous method invoked upon this object was neitherstartnorattributeIOException- If an I/O error occurs
-
attributeUnquoted
Writes an attribute (unquoted) for the current element.- Parameters:
prefix- The attribute's prefixname- The attribute's namevalue- The attribute's value- Throws:
IllegalStateException- If the previous method invoked upon this object was neitherstartnorattributeIOException- If an I/O error occurs
-
attributeName
Writes an attribute name for the current element. After invoking this method, invoke theattributeValuemethod to write the attribute value, or invoke theattributeValueTokenmethod to write one or more space-separated value tokens.- Parameters:
name- The attribute's name- Throws:
IllegalStateException- If the previous method invoked upon this object was neitherstartnorattributeIOException
-
attributeName
Writes an attribute name for the current element. After invoking this method, invoke theattributeValuemethod to write the attribute value, or invoke theattributeValueTokenmethod to write one or more space-separated value tokens.- Parameters:
prefix- The attribute's prefixname- The attribute's name- Throws:
IllegalStateException- If the previous method invoked upon this object was neitherstartnorattributeIOException
-
attributeValue
Writes a value for the current attribute.- Parameters:
value- The attribute's value- Throws:
IllegalStateException- If the previous method invoked upon this object was notattributeNameIOException
-
attributeValueUnquoted
Writes a value (unquoted) for the current attribute.- Parameters:
value- The attribute's value- Throws:
IllegalStateException- If the previous method invoked upon this object was notattributeNameIOException
-
attributeValueToken
Writes one token of the current attribute's value. Adjacent tokens will be separated by single space characters.- Parameters:
token- The token to be written- Throws:
IllegalStateException- If the previous method invoked upon this object was neitherattributeNamenorattributeValueTokenIOException
-
end
Writes an end tag for the named element.- Parameters:
name- The name to be used in the end tag- Throws:
IOException- If an I/O error occurs
-
chars
Writes some character data.- Parameters:
chars- The character data to be written- Throws:
IOException- If an I/O error occurs
-
chars
- Throws:
IOException
-
charsUnquoted
Writes some character data, skipping quoting.- Parameters:
chars- The character data to be written- Throws:
IOException- If an I/O error occurs
-
charsUnquoted
Writes some character data, skipping quoting.- Parameters:
cbuf- Buffer containing the character data to be writtenoff- The offset of the data to be writtenlen- The length of the data to be written- Throws:
IOException- If an I/O error occurs
-
leaf
Writes a leaf element with the given character content.- Parameters:
name- The name to be used in the start and end tagschars- The character data to be writtenThis 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.
- Throws:
IOException- If an I/O error occurs
-
inlineLeaf
- Throws:
IOException
-
leaf
Writes an empty leaf element.- Parameters:
name- The name to be used in the empty-element tag- Throws:
IOException
-
inlineLeaf
- Throws:
IOException
-
flush
Flushes the writer.- Throws:
IOException- If an I/O error occurs
-
close
Flushes the writer and closes the underlying byte-output stream.- Throws:
IOException- If an I/O error occurs
-