Class XmlWriter
- All Implemented Interfaces:
AutoCloseable
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the XML stream.flush()Flushes any un-flushed content that has been written to theXmlWriter.static XmlWriterfromXmlStreamWriter(XMLStreamWriter writer) Creates an instance ofXmlWriterthat writes to the providedXMLStreamWriter.static XmlWritertoStream(OutputStream xml) Creates an instance ofXmlWriterthat writes to the providedOutputStream.static XmlWriterwriteBinary(byte[] value) Writes a binary value as a base64 string.writeBinaryAttribute(String localName, byte[] value) Writes a binary attribute as a base64 string (attribute="value").writeBinaryAttribute(String namespaceUri, String localName, byte[] value) Writes a binary attribute as a base64 string that has a prefix (prefix:attribute="value").writeBinaryElement(String localName, byte[] value) Writes a binary element as a base64 string (<tag>value</tag).writeBinaryElement(String namespaceUri, String localName, byte[] value) Writes a binary element as a base64 string that has a prefix (<tag>value</tag).writeBoolean(boolean value) Writes a boolean value.writeBoolean(Boolean value) Writes a nullable boolean value.writeBooleanAttribute(String localName, boolean value) Writes a boolean attribute (attribute="true").writeBooleanAttribute(String localName, Boolean value) Writes a nullable boolean attribute (attribute="false").writeBooleanAttribute(String namespaceUri, String localName, boolean value) Writes a boolean attribute that has a prefix (prefix:attribute="true").writeBooleanAttribute(String namespaceUri, String localName, Boolean value) Writes a nullable boolean attribute that has a prefix (prefix:attribute="false").writeBooleanElement(String localName, boolean value) Writes a boolean element (<tag>true</tag).writeBooleanElement(String localName, Boolean value) Writes a nullable boolean element (<tag>true</tag).writeBooleanElement(String namespaceUri, String localName, boolean value) Writes a boolean element that has a prefix (<tag>true</tag).writeBooleanElement(String namespaceUri, String localName, Boolean value) Writes a nullable boolean element that has a prefix (<tag>true</tag).writeCDataString(String value) Writes a CData value directly into an XML element (<tag><![CDATA[value]]></tag>).writeDouble(double value) Writes a double value.writeDoubleAttribute(String localName, double value) Writes a double attribute (attribute="3.14").writeDoubleAttribute(String namespaceUri, String localName, double value) Writes a double attribute that has a prefix (prefix:attribute="3.14").writeDoubleElement(String localName, double value) Writes a double element (<tag>3.14</tag).writeDoubleElement(String namespaceUri, String localName, double value) Writes a double element that has a prefix (<tag>3.14</tag).Ends the current XML element by writing the closing tag (</tag>).writeFloat(float value) Writes a float value.writeFloatAttribute(String localName, float value) Writes a float attribute (attribute="2.7").writeFloatAttribute(String namespaceUri, String localName, float value) Writes a float attribute that has a prefix (prefix:attribute="2.7").writeFloatElement(String localName, float value) Writes a float element (<tag>2.7</tag).writeFloatElement(String namespaceUri, String localName, float value) Writes a float element that has a prefix (<tag>2.7</tag).writeInt(int value) Writes an int value.writeIntAttribute(String localName, int value) Writes an int attribute (attribute="10").writeIntAttribute(String namespaceUri, String localName, int value) Writes an int attribute that has a prefix (prefix:attribute="10").writeIntElement(String localName, int value) Writes an int element (<tag>10</tag).writeIntElement(String namespaceUri, String localName, int value) Writes an int element that has a prefix (<tag>10</tag).writeLong(long value) Writes a long value.writeLongAttribute(String localName, long value) Writes a long attribute (attribute="100000000000").writeLongAttribute(String namespaceUri, String localName, long value) Writes a long attribute that has a prefix (prefix:attribute="100000000000").writeLongElement(String localName, long value) Writes a long element (<tag>100000000000</tag).writeLongElement(String namespaceUri, String localName, long value) Writes a long element that has a prefix (<tag>100000000000</tag).writeNamespace(String namespaceUri) Writes a default XML namespace.writeNamespace(String namespacePrefix, String namespaceUri) Writes an XML namespace with a specified prefix.writeNumber(Number value) Writes a nullable number.writeNumberAttribute(String localName, Number value) Writes a nullable number attribute (attribute="number").writeNumberAttribute(String namespaceUri, String localName, Number value) Writes a nullable number attribute that has a prefix (prefix:attribute="number").writeNumberElement(String localName, Number value) Writes a nullable number element (<tag>number</tag).writeNumberElement(String namespaceUri, String localName, Number value) Writes a nullable number element that has a prefix (<tag>number</tag).Writes the XML document start (<?xml version="1.0" encoding="UTF-8">).writeStartDocument(String version, String encoding) Writes the XML document start (<?xml version="1.0" encoding="utf-8">).writeStartElement(String localName) Begins an XML element start (<tag).writeStartElement(String namespaceUri, String localName) Begins an XML element start that has a prefix (<prefix:tag).writeStartSelfClosingElement(String localName) Begins an XML element start that will be self-closing (<tag/>).writeStartSelfClosingElement(String namespaceUri, String localName) Begins an XML element start that has a prefix that will be self-closing (<prefix:tag/>).writeString(String value) Writes a value directly into an XML element (<tag>value</tag>).writeStringAttribute(String localName, String value) Writes a String attribute (attribute="value").writeStringAttribute(String namespaceUri, String localName, String value) Writes a String attribute that has a prefix (prefix:attribute="value").writeStringElement(String localName, String value) Writes a string element (<tag>string</tag).writeStringElement(String namespaceUri, String localName, String value) Writes a string element that has a prefix (<tag>string</tag).writeXml(XmlSerializable<?> value) Writes anXmlSerializableobject.writeXml(XmlSerializable<?> value, String rootElementName) Writes anXmlSerializableobject.
-
Method Details
-
toStream
Creates an instance ofXmlWriterthat writes to the providedOutputStream.This uses the
XMLStreamWriterimplementation provided by the defaultXMLOutputFactory.newInstance(). If you need to provide a custom implementation ofXMLStreamWriterusefromXmlStreamWriter(XMLStreamWriter).- Parameters:
xml- TheOutputStreamwhere content will be written.- Returns:
- A new instance of
XmlWriter. - Throws:
NullPointerException- Ifxmlis null.XMLStreamException- If anXmlWritercannot be instantiated.
-
toWriter
Creates an instance ofXmlWriterthat writes to the providedWriter.This uses the
XMLStreamWriterimplementation provided by the defaultXMLOutputFactory.newInstance(). If you need to provide a custom implementation ofXMLStreamWriterusefromXmlStreamWriter(XMLStreamWriter).- Parameters:
xml- TheWriterwhere content will be written.- Returns:
- A new instance of
XmlWriter. - Throws:
NullPointerException- Ifxmlis null.XMLStreamException- If anXmlWritercannot be instantiated.
-
fromXmlStreamWriter
Creates an instance ofXmlWriterthat writes to the providedXMLStreamWriter.- Parameters:
writer- TheXMLStreamWriterwhere content will be written.- Returns:
- A new instance of
XmlWriter. - Throws:
NullPointerException- Ifwriteris null.
-
writeStartDocument
Writes the XML document start (<?xml version="1.0" encoding="UTF-8">).This uses the default version and encoding which are
1.0andUTF-8respectively. If a different version or encoding is required usewriteStartDocument(String, String)which allows for specifying those values.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML start document cannot be written.
-
writeStartDocument
Writes the XML document start (<?xml version="1.0" encoding="utf-8">).Both
versionandencodingare optional and if they aren't passed their default values will be used. Forversionthe default is1.0and forencodingthe default isUTF-8.- Parameters:
version- XML document version.encoding- XML document encoding.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML start document cannot be written.
-
writeStartElement
Begins an XML element start (<tag).This call doesn't close (
>) the XML element start but instead defers it until a call to begin another element or to write the body of the element. This also requires an explicit call towriteEndElement()to end the XML element's body.Calls to write attributes won't close the XML element.
- Parameters:
localName- Name of the element.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element start cannot be written.
-
writeStartElement
Begins an XML element start that has a prefix (<prefix:tag).This call doesn't close (
>) the XML element start but instead defers it until a call to begin another element or to write the body of the element. This also requires an explicit call towriteEndElement()to end the XML element's body.Calls to write attributes won't close the XML element.
If
prefixis null this will behave the same aswriteStartElement(String).- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element start cannot be written.
-
writeStartSelfClosingElement
Begins an XML element start that will be self-closing (<tag/>).This call doesn't close (
/>) the XML element start but instead defers it until a call to begin another element. If there is an attempt to write the body of the element after beginning a self-closing element anIllegalStateExceptionwill be thrown as self-closing elements do not have a body.Calls to write attributes won't close the XML element.
- Parameters:
localName- Name of the element.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element start cannot be written.
-
writeStartSelfClosingElement
public XmlWriter writeStartSelfClosingElement(String namespaceUri, String localName) throws XMLStreamException Begins an XML element start that has a prefix that will be self-closing (<prefix:tag/>).This call doesn't close (
/>) the XML element start but instead defers it until a call to begin another element. If there is an attempt to write the body of the element after beginning a self-closing element anIllegalStateExceptionwill be thrown as self-closing elements do not have a body.Calls to write attributes won't close the XML element.
If
prefixis null this will behave the same aswriteStartSelfClosingElement(String).- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element start cannot be written.
-
writeEndElement
Ends the current XML element by writing the closing tag (</tag>).This call will determine the XML element tag name and prefix, if there is one, to close the current XML element scope.
- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element end cannot be written.
-
writeNamespace
Writes a default XML namespace.- Parameters:
namespaceUri- Namespace URI to bind as the default namespace.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML namespace cannot be written.
-
writeNamespace
public XmlWriter writeNamespace(String namespacePrefix, String namespaceUri) throws XMLStreamException Writes an XML namespace with a specified prefix.If the
namespacePrefixis null orxmlnscalling this method is equivalent towriteNamespace(String).- Parameters:
namespacePrefix- Prefix that the namespace binds.namespaceUri- Namespace URI to bind to the prefix.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML namespace cannot be written.
-
writeStringAttribute
Writes a String attribute (attribute="value").- Parameters:
localName- Name of the attribute.value- Value of the attribute.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeStringAttribute
public XmlWriter writeStringAttribute(String namespaceUri, String localName, String value) throws XMLStreamException Writes a String attribute that has a prefix (prefix:attribute="value").- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the attribute.value- Value of the attribute.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeBinaryAttribute
Writes a binary attribute as a base64 string (attribute="value").If the
valueis null this is a no-op.- Parameters:
localName- Name of the attribute.value- Binary value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeBinaryAttribute
public XmlWriter writeBinaryAttribute(String namespaceUri, String localName, byte[] value) throws XMLStreamException Writes a binary attribute as a base64 string that has a prefix (prefix:attribute="value").If the
valueis null this is a no-op.- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the attribute.value- Binary value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeBooleanAttribute
Writes a boolean attribute (attribute="true").- Parameters:
localName- Name of the attribute.value- boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeBooleanAttribute
public XmlWriter writeBooleanAttribute(String namespaceUri, String localName, boolean value) throws XMLStreamException Writes a boolean attribute that has a prefix (prefix:attribute="true").- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the attribute.value- boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeBooleanAttribute
Writes a nullable boolean attribute (attribute="false").If the
valueis null this is a no-op.- Parameters:
localName- Name of the attribute.value- Boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeBooleanAttribute
public XmlWriter writeBooleanAttribute(String namespaceUri, String localName, Boolean value) throws XMLStreamException Writes a nullable boolean attribute that has a prefix (prefix:attribute="false").If the
valueis null this is a no-op.- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the attribute.value- Boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeDoubleAttribute
Writes a double attribute (attribute="3.14").- Parameters:
localName- Name of the attribute.value- double value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeDoubleAttribute
public XmlWriter writeDoubleAttribute(String namespaceUri, String localName, double value) throws XMLStreamException Writes a double attribute that has a prefix (prefix:attribute="3.14").- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the attribute.value- double value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeFloatAttribute
Writes a float attribute (attribute="2.7").- Parameters:
localName- Name of the attribute.value- float value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeFloatAttribute
public XmlWriter writeFloatAttribute(String namespaceUri, String localName, float value) throws XMLStreamException Writes a float attribute that has a prefix (prefix:attribute="2.7").- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the attribute.value- float value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeIntAttribute
Writes an int attribute (attribute="10").- Parameters:
localName- Name of the attribute.value- int value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeIntAttribute
public XmlWriter writeIntAttribute(String namespaceUri, String localName, int value) throws XMLStreamException Writes an int attribute that has a prefix (prefix:attribute="10").- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the attribute.value- int value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeLongAttribute
Writes a long attribute (attribute="100000000000").- Parameters:
localName- Name of the attribute.value- long value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeLongAttribute
public XmlWriter writeLongAttribute(String namespaceUri, String localName, long value) throws XMLStreamException Writes a long attribute that has a prefix (prefix:attribute="100000000000").- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the attribute.value- long value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeNumberAttribute
Writes a nullable number attribute (attribute="number").- Parameters:
localName- Name of the attribute.value- Number value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeNumberAttribute
public XmlWriter writeNumberAttribute(String namespaceUri, String localName, Number value) throws XMLStreamException Writes a nullable number attribute that has a prefix (prefix:attribute="number").- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the attribute.value- Number value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML attribute cannot be written.
-
writeBinaryElement
Writes a binary element as a base64 string (<tag>value</tag).If the
valueis null this is a no-op.- Parameters:
localName- Name of the element.value- Binary value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeBinaryElement
public XmlWriter writeBinaryElement(String namespaceUri, String localName, byte[] value) throws XMLStreamException Writes a binary element as a base64 string that has a prefix (<tag>value</tag).If the
valueis null this is a no-op.- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.value- Binary value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeBooleanElement
Writes a boolean element (<tag>true</tag).- Parameters:
localName- Name of the element.value- boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeBooleanElement
public XmlWriter writeBooleanElement(String namespaceUri, String localName, boolean value) throws XMLStreamException Writes a boolean element that has a prefix (<tag>true</tag).- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.value- boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeBooleanElement
Writes a nullable boolean element (<tag>true</tag).If the
valueis null this is a no-op.- Parameters:
localName- Name of the element.value- Boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeBooleanElement
public XmlWriter writeBooleanElement(String namespaceUri, String localName, Boolean value) throws XMLStreamException Writes a nullable boolean element that has a prefix (<tag>true</tag).If the
valueis null this is a no-op.- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.value- Boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeDoubleElement
Writes a double element (<tag>3.14</tag).- Parameters:
localName- Name of the element.value- double value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeDoubleElement
public XmlWriter writeDoubleElement(String namespaceUri, String localName, double value) throws XMLStreamException Writes a double element that has a prefix (<tag>3.14</tag).- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.value- double value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeFloatElement
Writes a float element (<tag>2.7</tag).- Parameters:
localName- Name of the element.value- float value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeFloatElement
public XmlWriter writeFloatElement(String namespaceUri, String localName, float value) throws XMLStreamException Writes a float element that has a prefix (<tag>2.7</tag).- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.value- float value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeIntElement
Writes an int element (<tag>10</tag).- Parameters:
localName- Name of the element.value- int value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeIntElement
public XmlWriter writeIntElement(String namespaceUri, String localName, int value) throws XMLStreamException Writes an int element that has a prefix (<tag>10</tag).- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.value- int value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeLongElement
Writes a long element (<tag>100000000000</tag).- Parameters:
localName- Name of the elementvalue- long value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeLongElement
public XmlWriter writeLongElement(String namespaceUri, String localName, long value) throws XMLStreamException Writes a long element that has a prefix (<tag>100000000000</tag).- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.value- long value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeNumberElement
Writes a nullable number element (<tag>number</tag).If the
valueis null this is a no-op.- Parameters:
localName- Name of the element.value- Number value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeNumberElement
public XmlWriter writeNumberElement(String namespaceUri, String localName, Number value) throws XMLStreamException Writes a nullable number element that has a prefix (<tag>number</tag).If the
valueis null this is a no-op.- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.value- Number value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeStringElement
Writes a string element (<tag>string</tag).If the
valueis null this is a no-op.- Parameters:
localName- Name of the element.value- String value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeStringElement
public XmlWriter writeStringElement(String namespaceUri, String localName, String value) throws XMLStreamException Writes a string element that has a prefix (<tag>string</tag).If the
valueis null this is a no-op.- Parameters:
namespaceUri- Namespace URI to bind the prefix to, if null the default namespace is used.localName- Name of the element.value- String value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML element and value cannot be written.
-
writeXml
Writes anXmlSerializableobject.If the
valueis null this is a no-op.- Parameters:
value-XmlSerializableobject to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML object cannot be written.
-
writeXml
public XmlWriter writeXml(XmlSerializable<?> value, String rootElementName) throws XMLStreamException Writes anXmlSerializableobject.If the
valueis null this is a no-op.If
rootElementNameis null this is the same as callingwriteXml(XmlSerializable).- Parameters:
value-XmlSerializableobject to write.rootElementName- Override of the XML element name defined by the object.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML object cannot be written.
-
writeBinary
Writes a binary value as a base64 string.If the
valueis null this is a no-op.- Parameters:
value- Binary value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML value cannot be written.
-
writeBoolean
Writes a boolean value.- Parameters:
value- boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML value cannot be written.
-
writeBoolean
Writes a nullable boolean value.If the
valueis null this is a no-op.- Parameters:
value- Boolean value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML value cannot be written.
-
writeDouble
Writes a double value.- Parameters:
value- double value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML value cannot be written.
-
writeFloat
Writes a float value.- Parameters:
value- float value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML value cannot be written.
-
writeInt
Writes an int value.- Parameters:
value- int value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML value cannot be written.
-
writeLong
Writes a long value.- Parameters:
value- long value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML value cannot be written.
-
writeNumber
Writes a nullable number.If
valueis null this is a no-op.- Parameters:
value- Number value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML value cannot be written.
-
writeString
Writes a value directly into an XML element (<tag>value</tag>).This doesn't write the XML element start tag or end tag.
writeCDataString(String)is a convenience API if an XML CData value needs to be written.- Parameters:
value- Value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML value cannot be written.
-
writeCDataString
Writes a CData value directly into an XML element (<tag><![CDATA[value]]></tag>).This doesn't write the XML element start tag or end tag.
This API is a convenience over
writeString(String)for CData values, it is possible to usewriteString(String)instead of this API.- Parameters:
value- CData value to write.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the XML CData value cannot be written.
-
flush
Flushes any un-flushed content that has been written to theXmlWriter.- Returns:
- The updated XmlWriter object.
- Throws:
XMLStreamException- If the un-flushed XML content could not be flushed.
-
close
Closes the XML stream.During closing the implementation of
XmlWritermust flush any un-flushed content.- Specified by:
closein interfaceAutoCloseable- Throws:
XMLStreamException- If the underlying content store fails to close.
-