public class XmlWriter extends Writer
The XmlWriter class is a subclass of Writer that provides additional
methods to write XML documents.
| Constructor and Description |
|---|
XmlWriter(OutputStream out)
Construct a new XmlWriter.
|
XmlWriter(OutputStream out,
boolean useNamespaces)
Construct a new XmlWriter that optionally ignores namespaces.
|
XmlWriter(Writer out)
Construct a new XmlWriter.
|
XmlWriter(Writer out,
boolean useNamespaces)
Construct a new XmlWriter that optionally ignores namespaces.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attribute(QName attribute,
boolean value)
Add an attribute to the current open tag.
|
void |
attribute(QName attribute,
byte value)
Add an attribute to the current open tag.
|
void |
attribute(QName attribute,
double value)
Add an attribute to the current open tag.
|
void |
attribute(QName attribute,
float value)
Add an attribute to the current open tag.
|
void |
attribute(QName attribute,
int value)
Add an attribute to the current open tag.
|
void |
attribute(QName attribute,
long value)
Add an attribute to the current open tag.
|
void |
attribute(QName attribute,
Object value)
Add an attribute to the current open tag.
|
void |
attribute(QName attribute,
String value)
Add an attribute to the current open tag.
|
void |
attribute(String name,
Object value) |
void |
attribute(String name,
String value) |
void |
cdata(String text)
Write the contents in a CDATA section.
|
void |
close()
Close the underlying output stream or writer.
|
void |
closeStartTag()
Close the current open start tag.
|
void |
comment(String comment)
Write an XML comment.
|
void |
docType(String dtd)
Write a DTD section.
|
void |
docType(String name,
String systemId)
Write a DOCTYPE declaration using a SYSTEM identifier.
|
void |
docType(String name,
String publicId,
String systemId)
Write a DOCTYPE declaration using a PUBLIC identifier.
|
void |
element(QName element,
Object content)
Write the element with the specified content.
|
void |
element(String local,
Object content) |
void |
emptyTag(QName element)
Write an empty tag.
|
void |
endDocument()
End a document, closing all tags and flushing the output.
|
void |
endTag()
Write the end tag for the current element.
|
void |
endTag(QName element)
Write the end tag for an element.
|
void |
endTag(String localPart) |
void |
endTagLn(QName element) |
void |
entityRef(char ch)
Write the entity reference for the specified character.
|
void |
entityRef(String name)
Write the entity reference with the specified text.
|
void |
flush()
Flush the output closing the current start tag.
|
String |
getPrefix(String namespaceUri)
Get the prefix for the XML Namespace URI.
|
boolean |
isIndent()
Get the flag indicating that the xml elements should be indented.
|
boolean |
isWriteNewLine() |
void |
newLine()
Write a newLine to the writer.
|
void |
nillableElement(QName element,
Object content)
Write the element with the specified content, if null xsi:nil attribute
will be set.
|
void |
processingInstruction(String target,
String value)
Write an XML processing instruction.
|
void |
setElementHasContent() |
void |
setIndent(boolean indent)
Set the flag indicating that the xml elements should be indented.
|
void |
setNamespaceAlias(String namespaceUri,
String alias) |
void |
setPrefix(QName typePath) |
void |
setPrefix(String prefix,
String namespaceUri)
Set the prefix for the XML Namespace URI.
|
void |
setWriteNewLine(boolean writeNewLine) |
void |
startDocument()
Start a document with an empty XML Declaration.
|
void |
startDocument(String encoding)
Start a document with an XML Declaration for the specified encoding.
|
void |
startDocument(String encoding,
boolean standalone)
Start a document with an XML Declaration for the specified encoding and the
standalone flag.
|
void |
startDocument(String encoding,
Boolean standalone)
Start a document with an XML Declaration for the specified encoding and the
standalone flag (null will omit the flag).
|
void |
startDocument(String encoding,
String version)
Start a document with an XML Declaration for the specified encoding.
|
void |
startDocument(String encoding,
String version,
Boolean standalone)
Start a document with an XML Declaration for the specified encoding and the
standalone flag (null will omit the flag).
|
void |
startTag(QName element)
Write the start tag for an element.
|
void |
startTag(String localPart) |
void |
startTag(String namespaceUri,
String localPart)
Write the start tag for an element.
|
void |
startTagLn(QName element) |
void |
text(boolean value)
Write the boolean value as the content of a tag with special characters
escaped.
|
void |
text(char[] buffer,
int offset,
int length)
Write a portion of the character buffer to the outpu, escaping special
characters.
|
void |
text(double value)
Write the double value as the content of a tag with special characters
escaped.
|
void |
text(float value)
Write the float value as the content of a tag with special characters
escaped.
|
void |
text(int value)
Write the int value as the content of a tag with special characters
escaped.
|
void |
text(long value)
Write the long value as the content of a tag with special characters
escaped.
|
void |
text(Object value)
Write the object value as the content of a tag with special characters
escaped.
|
void |
text(String text)
Write the text string to the output, escaping special characters.
|
void |
write(char[] buffer)
Write an array of characters.
|
void |
write(char[] buffer,
int offset,
int length)
Write a portion of an array of characters.
|
void |
write(int character)
Write a single character.
|
void |
write(String string)
Write a String.
|
void |
write(String string,
int offset,
int length)
Write a portion of a String.
|
protected void |
writeAttributeContent(char[] buffer,
int offset,
int length)
Write content for an attribute value to the output, escaping the characters
that are used within markup.
|
protected void |
writeAttributeValue(String value)
Write the value of an attribute.
|
protected void |
writeElementContent(char[] buffer,
int offest,
int length)
Write content for an element to the output, escaping the characters that
are used within markup.
|
void |
writeNamespaceAttribute(String namespaceUri,
String prefix) |
void |
xsiTypeAttribute(QName xsiTagName) |
public XmlWriter(OutputStream out)
out - The output stream to write to.public XmlWriter(OutputStream out, boolean useNamespaces)
out - The output stream to write to.useNamespaces - True if namespaces should be written, false if they
should be ignored.public XmlWriter(Writer out)
out - The writer to write to.public XmlWriter(Writer out, boolean useNamespaces)
out - The writer to write to.useNamespaces - True if namespaces should be written, false if they
should be ignored.public void attribute(QName attribute, boolean value)
attribute - The QName of the attribute.value - The attribute value.IOException - If there was an error writing.IllegalStateException - If a start tag is not open.public void attribute(QName attribute, byte value)
attribute - The QName of the attribute.value - The attribute value.IOException - If there was an error writing.IllegalStateException - If a start tag is not open.public void attribute(QName attribute, double value)
attribute - The QName of the attribute.value - The attribute value.IOException - If there was an error writing.IllegalStateException - If a start tag is not open.public void attribute(QName attribute, float value)
attribute - The QName of the attribute.value - The attribute value.IOException - If there was an error writing.IllegalStateException - If a start tag is not open.public void attribute(QName attribute, int value)
attribute - The QName of the attribute.value - The attribute value.IOException - If there was an error writing.IllegalStateException - If a start tag is not open.public void attribute(QName attribute, long value)
attribute - The QName of the attribute.value - The attribute value.IOException - If there was an error writing.IllegalStateException - If a start tag is not open.public void attribute(QName attribute, Object value)
attribute - The QName of the attribute.value - The attribute value.IOException - If there was an error writing.IllegalStateException - If a start tag is not open.public void attribute(QName attribute, String value)
attribute - The QName of the attribute.value - The attribute value.IOException - If there was an error writing.IllegalStateException - If a start tag is not open.public void cdata(String text)
text - The text to wrap in a CDATA sectionIOException - If there was a problem writing the textpublic void close()
close in interface Closeableclose in interface AutoCloseableclose in class WriterIOException - If the output stream or writer could not be closed.public void closeStartTag()
IOException - If there was an error writing.public void comment(String comment)
comment - The comment to writeIOException - If there was a problem writing the commentpublic void docType(String dtd)
dtd - The DTD to be writtenIOException - If there was a problem writing the declarationpublic void docType(String name, String systemId)
name - The root element namesystemId - The system idIOException - If there was a problem writing the declarationpublic void docType(String name, String publicId, String systemId)
name - The root element name.publicId - The public id.systemId - The system id.IOException - If there was a problem writing the declaration.public void element(QName element, Object content)
element - The QName of the tag.content - The body context for the element.IOException - If there was a problem writing the element.public void emptyTag(QName element)
element - The QName of the tag.IOException - If there was a problem writing the tag.public void endDocument()
IOException - If the document could not be endedpublic void endTag()
IOException - If there was a problem writing the element.public void endTag(QName element)
element - The QName of the tag.IOException - If there was a problem writing the element.public void endTag(String localPart)
public void endTagLn(QName element)
public void entityRef(char ch)
ch - The character to write the entity forIOException - If there was a problem writing the entitypublic void entityRef(String name)
name - The name of the entityIOException - If there was a problem writing the entitypublic void flush()
flush in interface Flushableflush in class WriterIOException - If there was an exception flushing the writer.public String getPrefix(String namespaceUri)
namespaceUri - The XML Namespace URI.public boolean isIndent()
public boolean isWriteNewLine()
public void newLine()
IOException - If there was an exception writing the new line.public void nillableElement(QName element, Object content)
element - The QName of the tag.content - The body context for the element.IOException - If there was a problem writing the element.public void processingInstruction(String target, String value)
target - The PI Target (must not be xml)value - The value of the processing instructionIOException - If there was a problem writing the commentpublic void setElementHasContent()
public void setIndent(boolean indent)
indent - The flag indicating that the xml elements should be indented.public void setPrefix(QName typePath)
public void setPrefix(String prefix, String namespaceUri)
prefix - The prefix.namespaceUri - The XML Namespace URI.public void setWriteNewLine(boolean writeNewLine)
public void startDocument()
IOException - If there was a problem writing the XML Declaration.public void startDocument(String encoding)
encoding - The encoding for the documentIOException - If there was a problem writing the XML Declaration.public void startDocument(String encoding, boolean standalone)
encoding - The encoding for the documentstandalone - The standalone flagIOException - If there was a problem writing the XML Declaration.public void startDocument(String encoding, Boolean standalone)
encoding - The encoding for the documentstandalone - The standalone flagIOException - If there was a problem writing the XML Declaration.public void startDocument(String encoding, String version)
encoding - The encoding for the documentversion - The XML version.IOException - If there was a problem writing the XML Declaration.public void startDocument(String encoding, String version, Boolean standalone)
encoding - The encoding for the documentversion - The XML version.standalone - The standalone flagIOException - If there was a problem writing the XML Declaration.public void startTag(QName element)
element - The QName of the tag.IOException - If there was a problem writing the element.public void startTag(String localPart)
public void startTag(String namespaceUri, String localPart)
namespaceUri - The namespace URI.localPart - The local name.IOException - If there was a problem writing the element.public void startTagLn(QName element)
public void text(boolean value)
value - The value.IOException - If there was a problem writing the text.public void text(char[] buffer,
int offset,
int length)
buffer - The buffer to write.offset - The starting offset in the buffer.length - The number of characters to write.IOException - If there was a problem writing the text.public void text(double value)
value - The value.IOException - If there was a problem writing the text.public void text(float value)
value - The value.IOException - If there was a problem writing the text.public void text(int value)
value - The value.IOException - If there was a problem writing the text.public void text(long value)
value - The value.IOException - If there was a problem writing the text.public void text(Object value)
value - The value.IOException - If there was a problem writing the text.public void text(String text)
text - The text to writeIOException - If there was a problem writing the textpublic void write(char[] buffer)
write in class Writerbuffer - The character buffer to write.IOException - If an I/O exception occurs.public void write(char[] buffer,
int offset,
int length)
write in class Writerbuffer - The character buffer to write.offset - The starting offset in the buffer.length - The number of characters to write.IOException - If an I/O exception occurs.public void write(int character)
write in class Writercharacter - The character to write.IOException - If an I/O exception occurs.public void write(String string)
write in class Writerstring - The String to write.IOException - If an I/O exception occurs.public void write(String string, int offset, int length)
write in class Writerstring - The String to write.offset - The starting offset in the buffer.length - The number of characters to write.IOException - If an I/O exception occurs.protected void writeAttributeContent(char[] buffer,
int offset,
int length)
buffer - The character buffer to writeoffset - The offset in the character data to writelength - The number of characters to write.IOException - If an I/O exception occurs.protected void writeAttributeValue(String value)
value - The value to write.IOException - If an I/O exception occurs.protected void writeElementContent(char[] buffer,
int offest,
int length)
buffer - The character buffer to writeoffest - The offset in the character data to writelength - The number of characters to write.IOException - If an I/O exception occurs.public void xsiTypeAttribute(QName xsiTagName)
Copyright © 2015 Revolution Systems Inc.. All rights reserved.