public class XmlStreamWriter extends Object implements StreamWriter
StreamWriter for handling XML.| Constructor and Description |
|---|
XmlStreamWriter(OutputStream os)
Creates a
StreamWriter for handling XML, with a null
prefix and postfix. |
XmlStreamWriter(OutputStream os,
String prefix,
String postfix)
Creates a
StreamWriter for handling XML. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the
OutputStream associated with this object. |
String |
getPostfix()
Returns a string of data that must appear at the end of the data stream.
|
String |
getPrefix()
Returns a string of data that must appear at the start of the data
stream.
|
void |
writeAttribute(String name,
Boolean value)
Writes a
Boolean attribute with the specified name and
value. |
void |
writeAttribute(String name,
String value)
Writes a
String attribute with the specified name and
value. |
void |
writeEndArray()
Writes the end of an array.
|
void |
writeEndDocument()
Writes the data that is compulsory to appear at the end of the data
structure.
|
void |
writeEndObject()
Writes the end of an object.
|
void |
writeStartArray(String element)
Writes the start of an array, with the specified
name. |
void |
writeStartDocument()
Writes the data that is compulsory to appear at the start of the data
structure.
|
void |
writeStartObject(String element)
Writes the start of a new object, with the specified
name. |
public XmlStreamWriter(OutputStream os, String prefix, String postfix) throws XMLStreamException
StreamWriter for handling XML.os - The OutputStream to write to.prefix - Any data that needs writing at the start of the stream.postfix - Any data that needs writing at the end of the stream.XMLStreamException - Thrown if any errors occur in
creating the XML stream.public XmlStreamWriter(OutputStream os) throws XMLStreamException
StreamWriter for handling XML, with a null
prefix and postfix.os - The OutputStream to write to.XMLStreamException - Thrown if any errors occur in
creating the XML stream.public String getPostfix()
StreamWritergetPostfix in interface StreamWriterpublic String getPrefix()
StreamWritergetPrefix in interface StreamWriterpublic void writeStartDocument()
throws XMLStreamException,
IOException
StreamWriter<?xml version="1.0" ?>writeStartDocument in interface StreamWriterXMLStreamExceptionIOExceptionpublic void writeEndDocument()
throws XMLStreamException,
IOException
StreamWriterwriteEndDocument in interface StreamWriterXMLStreamExceptionIOExceptionpublic void writeStartObject(String element) throws XMLStreamException
StreamWritername.writeStartObject in interface StreamWriterelement - The name of the objectXMLStreamExceptionpublic void writeEndObject()
throws XMLStreamException
StreamWriterwriteEndObject in interface StreamWriterXMLStreamExceptionpublic void writeAttribute(String name, String value) throws XMLStreamException
StreamWriterString attribute with the specified name and
value. E.g. for JSON this will write: "name":"value".writeAttribute in interface StreamWritername - The name of the attributevalue - The value of the attributeXMLStreamExceptionpublic void writeAttribute(String name, Boolean value) throws XMLStreamException
StreamWriterBoolean attribute with the specified name and
value. E.g. for JSON this will write: "name":true/false.writeAttribute in interface StreamWritername - The name of the attributevalue - The value of the attributeXMLStreamExceptionpublic void close()
throws XMLStreamException
StreamWriterOutputStream associated with this object. Some
OutputStreams require closing before any data will be written.close in interface StreamWriterXMLStreamExceptionpublic void writeStartArray(String element) throws Exception
StreamWritername. If the
data structure doesn't support arrays, this method will do nothing.writeStartArray in interface StreamWriterelement - The name of the arrayException - Any exception thrown while writing. E.g. for JSON this
might be a
JsonGenerationException.public void writeEndArray()
throws Exception
StreamWriterwriteEndArray in interface StreamWriterException - Any exception thrown while writing. E.g. for JSON this
might be a
JsonGenerationException.Copyright © 2019. All rights reserved.