XmlWriter Class

  • java.lang.Object
    • com.azure.xml.XmlWriter

Implements

public abstract class XmlWriter
implements AutoCloseable

Writes an XML encoded value to a stream.

Constructor Summary

Constructor Description
XmlWriter()

Creates an instance of XmlWriter.

Method Summary

Modifier and Type Method and Description
abstract void close()

Closes the XML stream.

abstract XmlWriter flush()

Flushes any un-flushed content that has been written to the XmlWriter.

final XmlWriter writeBinary(byte[] value)

Writes a binary value as a base64 string.

final XmlWriter writeBinaryAttribute(String localName, byte[] value)

Writes a binary attribute as a base64 string (attribute="value").

final XmlWriter writeBinaryAttribute(String namespaceUri, String localName, byte[] value)

Writes a binary attribute as a base64 string that has a prefix (prefix:attribute="value").

final XmlWriter writeBinaryElement(String localName, byte[] value)

Writes a binary element as a base64 string (value).

final XmlWriter writeBinaryElement(String namespaceUri, String localName, byte[] value)

Writes a binary element as a base64 string that has a prefix (value).

final XmlWriter writeBoolean(boolean value)

Writes a boolean value.

final XmlWriter writeBoolean(Boolean value)

Writes a nullable boolean value.

final XmlWriter writeBooleanAttribute(String localName, boolean value)

Writes a boolean attribute (attribute="true").

final XmlWriter writeBooleanAttribute(String localName, Boolean value)

Writes a nullable boolean attribute (attribute="false").

final XmlWriter writeBooleanAttribute(String namespaceUri, String localName, boolean value)

Writes a boolean attribute that has a prefix (prefix:attribute="true").

final XmlWriter writeBooleanAttribute(String namespaceUri, String localName, Boolean value)

Writes a nullable boolean attribute that has a prefix (prefix:attribute="false").

final XmlWriter writeBooleanElement(String localName, boolean value)

Writes a boolean element (true).

final XmlWriter writeBooleanElement(String localName, Boolean value)

Writes a nullable boolean element (true).

final XmlWriter writeBooleanElement(String namespaceUri, String localName, boolean value)

Writes a boolean element that has a prefix (true).

final XmlWriter writeBooleanElement(String namespaceUri, String localName, Boolean value)

Writes a nullable boolean element that has a prefix (true).

abstract XmlWriter writeCDataString(String value)

Writes a CData value directly into an XML element (value).

final XmlWriter writeDouble(double value)

Writes a double value.

final XmlWriter writeDoubleAttribute(String localName, double value)

Writes a double attribute (attribute="3.14").

final XmlWriter writeDoubleAttribute(String namespaceUri, String localName, double value)

Writes a double attribute that has a prefix (prefix:attribute="3.14").

final XmlWriter writeDoubleElement(String localName, double value)

Writes a double element (3.14).

final XmlWriter writeDoubleElement(String namespaceUri, String localName, double value)

Writes a double element that has a prefix (3.14).

abstract XmlWriter writeEndElement()

Ends the current XML element by writing the closing tag (``).

final XmlWriter writeFloat(float value)

Writes a float value.

final XmlWriter writeFloatAttribute(String localName, float value)

Writes a float attribute (attribute="2.7").

final XmlWriter writeFloatAttribute(String namespaceUri, String localName, float value)

Writes a float attribute that has a prefix (prefix:attribute="2.7").

final XmlWriter writeFloatElement(String localName, float value)

Writes a float element (2.7).

final XmlWriter writeFloatElement(String namespaceUri, String localName, float value)

Writes a float element that has a prefix (2.7).

final XmlWriter writeInt(int value)

Writes an int value.

final XmlWriter writeIntAttribute(String localName, int value)

Writes an int attribute (attribute="10").

final XmlWriter writeIntAttribute(String namespaceUri, String localName, int value)

Writes an int attribute that has a prefix (prefix:attribute="10").

final XmlWriter writeIntElement(String localName, int value)

Writes an int element (10).

final XmlWriter writeIntElement(String namespaceUri, String localName, int value)

Writes an int element that has a prefix (10).

final XmlWriter writeLong(long value)

Writes a long value.

final XmlWriter writeLongAttribute(String namespaceUri, String localName, long value)

Writes a long attribute that has a prefix (prefix:attribute="100000000000").

final XmlWriter writeLongAttribute(String localName, long value)

Writes a long attribute (attribute="100000000000").

final XmlWriter writeLongElement(String namespaceUri, String localName, long value)

Writes a long element that has a prefix (100000000000).

final XmlWriter writeLongElement(String localName, long value)

Writes a long element (100000000000).

abstract XmlWriter writeNamespace(String namespaceUri)

Writes a default XML namespace.

abstract XmlWriter writeNamespace(String namespacePrefix, String namespaceUri)

Writes an XML namespace with a specified prefix.

final XmlWriter writeNumber(Number value)

Writes a nullable number.

final XmlWriter writeNumberAttribute(String localName, Number value)

Writes a nullable number attribute (attribute="number").

final XmlWriter writeNumberAttribute(String namespaceUri, String localName, Number value)

Writes a nullable number attribute that has a prefix (prefix:attribute="number").

final XmlWriter writeNumberElement(String localName, Number value)

Writes a nullable number element (number).

final XmlWriter writeNumberElement(String namespaceUri, String localName, Number value)

Writes a nullable number element that has a prefix (number).

final XmlWriter writeStartDocument()

Writes the XML document start (``).

abstract XmlWriter writeStartDocument(String version, String encoding)

Writes the XML document start (``).

final XmlWriter writeStartElement(String localName)

Begins an XML element start (``).

abstract XmlWriter writeStartElement(String namespaceUri, String localName)

Begins an XML element start that has a prefix (``).

final XmlWriter writeStartSelfClosingElement(String localName)

Begins an XML element start that will be self-closing (``).

abstract XmlWriter writeStartSelfClosingElement(String namespaceUri, String localName)

Begins an XML element start that has a prefix that will be self-closing (``).

abstract XmlWriter writeString(String value)

Writes a value directly into an XML element (value).

final XmlWriter writeStringAttribute(String localName, String value)

Writes a String attribute (attribute="value").

abstract XmlWriter writeStringAttribute(String namespaceUri, String localName, String value)

Writes a String attribute that has a prefix (prefix:attribute="value").

final XmlWriter writeStringElement(String localName, String value)

Writes a string element (string).

final XmlWriter writeStringElement(String namespaceUri, String localName, String value)

Writes a string element that has a prefix (string).

final XmlWriter writeXml(XmlSerializable<?> value)

Writes an XmlSerializable<T> object.

final XmlWriter writeXml(XmlSerializable<?> value, String rootElementName)

Writes an XmlSerializable<T> object.

Methods inherited from java.lang.Object

Constructor Details

XmlWriter

public XmlWriter()

Creates an instance of XmlWriter.

Method Details

close

public abstract void close()

Closes the XML stream.

During closing the implementation of XmlWriter must flush any un-flushed content.

Throws:

XMLStreamException

- If the underlying content store fails to close.

flush

public abstract XmlWriter flush()

Flushes any un-flushed content that has been written to the XmlWriter.

Returns:

The updated XmlWriter object.

Throws:

XMLStreamException

- If the un-flushed XML content could not be flushed.

writeBinary

public final XmlWriter writeBinary(byte[] value)

Writes a binary value as a base64 string.

If the value is 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.

writeBinaryAttribute

public final XmlWriter writeBinaryAttribute(String localName, byte[] value)

Writes a binary attribute as a base64 string (attribute="value").

If the value is 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 final XmlWriter writeBinaryAttribute(String namespaceUri, String localName, byte[] value)

Writes a binary attribute as a base64 string that has a prefix (prefix:attribute="value").

If the value is 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.

writeBinaryElement

public final XmlWriter writeBinaryElement(String localName, byte[] value)

Writes a binary element as a base64 string (value).

If the value is 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 final XmlWriter writeBinaryElement(String namespaceUri, String localName, byte[] value)

Writes a binary element as a base64 string that has a prefix (value).

If the value is 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.

writeBoolean

public final XmlWriter writeBoolean(boolean value)

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

public final XmlWriter writeBoolean(Boolean value)

Writes a nullable boolean value.

If the value is 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.

writeBooleanAttribute

public final XmlWriter writeBooleanAttribute(String localName, boolean value)

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 final XmlWriter writeBooleanAttribute(String localName, Boolean value)

Writes a nullable boolean attribute (attribute="false").

If the value is 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 final XmlWriter writeBooleanAttribute(String namespaceUri, String localName, boolean value)

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

public final XmlWriter writeBooleanAttribute(String namespaceUri, String localName, Boolean value)

Writes a nullable boolean attribute that has a prefix (prefix:attribute="false").

If the value is 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.

writeBooleanElement

public final XmlWriter writeBooleanElement(String localName, boolean value)

Writes a boolean element (true).

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 final XmlWriter writeBooleanElement(String localName, Boolean value)

Writes a nullable boolean element (true).

If the value is 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 final XmlWriter writeBooleanElement(String namespaceUri, String localName, boolean value)

Writes a boolean element that has a prefix (true).

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

public final XmlWriter writeBooleanElement(String namespaceUri, String localName, Boolean value)

Writes a nullable boolean element that has a prefix (true).

If the value is 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.

writeCDataString

public abstract XmlWriter writeCDataString(String value)

Writes a CData value directly into an XML element (value).

This doesn't write the XML element start tag or end tag.

This API is a convenience over writeString(String value) for CData values, it is possible to use writeString(String value) 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.

writeDouble

public final XmlWriter writeDouble(double value)

Writes a double value.

Parameters:

value - double value to write.

Returns:

The updated XmlWriter object.

Throws:

XMLStreamException

- If the XML value cannot be written.

writeDoubleAttribute

public final XmlWriter writeDoubleAttribute(String localName, double value)

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 final XmlWriter writeDoubleAttribute(String namespaceUri, String localName, double value)

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.

writeDoubleElement

public final XmlWriter writeDoubleElement(String localName, double value)

Writes a double element (3.14).

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 final XmlWriter writeDoubleElement(String namespaceUri, String localName, double value)

Writes a double element that has a prefix (3.14).

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.

writeEndElement

public abstract XmlWriter writeEndElement()

Ends the current XML element by writing the closing 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.

writeFloat

public final XmlWriter writeFloat(float value)

Writes a float value.

Parameters:

value - float value to write.

Returns:

The updated XmlWriter object.

Throws:

XMLStreamException

- If the XML value cannot be written.

writeFloatAttribute

public final XmlWriter writeFloatAttribute(String localName, float value)

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 final XmlWriter writeFloatAttribute(String namespaceUri, String localName, float value)

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.

writeFloatElement

public final XmlWriter writeFloatElement(String localName, float value)

Writes a float element (2.7).

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 final XmlWriter writeFloatElement(String namespaceUri, String localName, float value)

Writes a float element that has a prefix (2.7).

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.

writeInt

public final XmlWriter writeInt(int value)

Writes an int value.

Parameters:

value - int value to write.

Returns:

The updated XmlWriter object.

Throws:

XMLStreamException

- If the XML value cannot be written.

writeIntAttribute

public final XmlWriter writeIntAttribute(String localName, int value)

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 final XmlWriter writeIntAttribute(String namespaceUri, String localName, int value)

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.

writeIntElement

public final XmlWriter writeIntElement(String localName, int value)

Writes an int element (10).

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 final XmlWriter writeIntElement(String namespaceUri, String localName, int value)

Writes an int element that has a prefix (10).

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.

writeLong

public final XmlWriter writeLong(long value)

Writes a long value.

Parameters:

value - long value to write.

Returns:

The updated XmlWriter object.

Throws:

XMLStreamException

- If the XML value cannot be written.

writeLongAttribute

public final XmlWriter writeLongAttribute(String namespaceUri, String localName, long value)

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.

writeLongAttribute

public final XmlWriter writeLongAttribute(String localName, long value)

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.

writeLongElement

public final XmlWriter writeLongElement(String namespaceUri, String localName, long value)

Writes a long element that has a prefix (100000000000).

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.

writeLongElement

public final XmlWriter writeLongElement(String localName, long value)

Writes a long element (100000000000).

Parameters:

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.

writeNamespace

public abstract XmlWriter writeNamespace(String namespaceUri)

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 abstract XmlWriter writeNamespace(String namespacePrefix, String namespaceUri)

Writes an XML namespace with a specified prefix.

If the namespacePrefix is null or xmlns calling this method is equivalent to writeNamespace(String namespaceUri).

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.

writeNumber

public final XmlWriter writeNumber(Number value)

Writes a nullable number.

If value is 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.

writeNumberAttribute

public final XmlWriter writeNumberAttribute(String localName, Number value)

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 final XmlWriter writeNumberAttribute(String namespaceUri, String localName, Number value)

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.

writeNumberElement

public final XmlWriter writeNumberElement(String localName, Number value)

Writes a nullable number element (number).

If the value is 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 final XmlWriter writeNumberElement(String namespaceUri, String localName, Number value)

Writes a nullable number element that has a prefix (number).

If the value is 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.

writeStartDocument

public final XmlWriter writeStartDocument()

Writes the XML document start (``).

This uses the default version and encoding which are 1.0 and UTF-8 respectively. If a different version or encoding is required use writeStartDocument(String version, String encoding) which allows for specifying those values.

Returns:

The updated XmlWriter object.

Throws:

XMLStreamException

- If the XML start document cannot be written.

writeStartDocument

public abstract XmlWriter writeStartDocument(String version, String encoding)

Writes the XML document start (``).

Both version and encoding are optional and if they aren't passed their default values will be used. For version the default is 1.0 and for encoding the default is UTF-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

public final XmlWriter writeStartElement(String localName)

Begins an XML element start (``).

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 to writeEndElement() 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

public abstract XmlWriter writeStartElement(String namespaceUri, String localName)

Begins an XML element start that has a prefix (``).

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 to writeEndElement() to end the XML element's body.

Calls to write attributes won't close the XML element.

If prefix is null this will behave the same as writeStartElement(String localName).

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

public final XmlWriter writeStartSelfClosingElement(String localName)

Begins an XML element start that will be self-closing (``).

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 an IllegalStateException will 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 abstract XmlWriter writeStartSelfClosingElement(String namespaceUri, String localName)

Begins an XML element start that has a prefix that will be self-closing (``).

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 an IllegalStateException will be thrown as self-closing elements do not have a body.

Calls to write attributes won't close the XML element.

If prefix is null this will behave the same as writeStartSelfClosingElement(String localName).

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.

writeString

public abstract XmlWriter writeString(String value)

Writes a value directly into an XML element (value).

This doesn't write the XML element start tag or end tag.

writeCDataString(String value) 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.

writeStringAttribute

public final XmlWriter writeStringAttribute(String localName, String value)

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 abstract XmlWriter writeStringAttribute(String namespaceUri, String localName, String value)

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.

writeStringElement

public final XmlWriter writeStringElement(String localName, String value)

Writes a string element (string).

If the value is 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 final XmlWriter writeStringElement(String namespaceUri, String localName, String value)

Writes a string element that has a prefix (string).

If the value is 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

public final XmlWriter writeXml(XmlSerializable value)

Writes an XmlSerializable<T> object.

If the value is null this is a no-op.

Parameters:

value - XmlSerializable<T> object to write.

Returns:

The updated XmlWriter object.

Throws:

XMLStreamException

- If the XML object cannot be written.

writeXml

public final XmlWriter writeXml(XmlSerializable value, String rootElementName)

Writes an XmlSerializable<T> object.

If the value is null this is a no-op.

If rootElementName is null this is the same as calling writeXml(XmlSerializable<?> value).

Parameters:

value - XmlSerializable<T> object 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.

Applies to