XmlWriter Class
- java.
lang. Object - com.
azure. xml. XmlWriter
- com.
Implements
public final class XmlWriter
implements AutoCloseable
Writes an XML encoded value to a stream.
Method Summary
Methods inherited from java.lang.Object
Method Details
close
public void close()
Closes the XML stream.
During closing the implementation of XmlWriter must flush any un-flushed content.
Throws:
flush
public XmlWriter flush()
Flushes any un-flushed content that has been written to the XmlWriter.
Returns:
Throws:
fromXmlStreamWriter
toStream
public static XmlWriter toStream(OutputStream xml)
Creates an instance of XmlWriter that writes to the provided OutputStream.
This uses the XMLStreamWriter implementation provided by the default XMLOutputFactory#newInstance(). If you need to provide a custom implementation of XMLStreamWriter use fromXmlStreamWriter(XMLStreamWriter writer).
Parameters:
Returns:
Throws:
xml
is null.
toWriter
public static XmlWriter toWriter(Writer xml)
Creates an instance of XmlWriter that writes to the provided Writer.
This uses the XMLStreamWriter implementation provided by the default XMLOutputFactory#newInstance(). If you need to provide a custom implementation of XMLStreamWriter use fromXmlStreamWriter(XMLStreamWriter writer).
Parameters:
Returns:
Throws:
xml
is null.
writeBinary
public XmlWriter writeBinary(byte[] value)
Writes a binary value as a base64 string.
If the value
is null this is a no-op.
Parameters:
Returns:
Throws:
writeBinaryAttribute
public 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:
Returns:
Throws:
writeBinaryAttribute
public 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:
Returns:
Throws:
writeBinaryElement
public 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:
Returns:
Throws:
writeBinaryElement
public 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:
Returns:
Throws:
writeBoolean
public XmlWriter writeBoolean(boolean value)
Writes a boolean value.
Parameters:
Returns:
Throws:
writeBoolean
public XmlWriter writeBoolean(Boolean value)
Writes a nullable boolean value.
If the value
is null this is a no-op.
Parameters:
Returns:
Throws:
writeBooleanAttribute
public XmlWriter writeBooleanAttribute(String localName, boolean value)
Writes a boolean attribute (attribute="true"
).
Parameters:
Returns:
Throws:
writeBooleanAttribute
public XmlWriter writeBooleanAttribute(String localName, Boolean value)
Writes a nullable boolean attribute (attribute="false"
).
If the value
is null this is a no-op.
Parameters:
Returns:
Throws:
writeBooleanAttribute
public XmlWriter writeBooleanAttribute(String namespaceUri, String localName, boolean value)
Writes a boolean attribute that has a prefix (prefix:attribute="true"
).
Parameters:
Returns:
Throws:
writeBooleanAttribute
public 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:
Returns:
Throws:
writeBooleanElement
public XmlWriter writeBooleanElement(String localName, boolean value)
Writes a boolean element (true
).
Parameters:
Returns:
Throws:
writeBooleanElement
public XmlWriter writeBooleanElement(String localName, Boolean value)
Writes a nullable boolean element (true
).
If the value
is null this is a no-op.
Parameters:
Returns:
Throws:
writeBooleanElement
public XmlWriter writeBooleanElement(String namespaceUri, String localName, boolean value)
Writes a boolean element that has a prefix (true
).
Parameters:
Returns:
Throws:
writeBooleanElement
public 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:
Returns:
Throws:
writeCDataString
public 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:
Returns:
Throws:
writeDouble
public XmlWriter writeDouble(double value)
Writes a double value.
Parameters:
Returns:
Throws:
writeDoubleAttribute
public XmlWriter writeDoubleAttribute(String localName, double value)
Writes a double attribute (attribute="3.14"
).
Parameters:
Returns:
Throws:
writeDoubleAttribute
public XmlWriter writeDoubleAttribute(String namespaceUri, String localName, double value)
Writes a double attribute that has a prefix (prefix:attribute="3.14"
).
Parameters:
Returns:
Throws:
writeDoubleElement
public XmlWriter writeDoubleElement(String localName, double value)
Writes a double element (3.14
).
Parameters:
Returns:
Throws:
writeDoubleElement
public XmlWriter writeDoubleElement(String namespaceUri, String localName, double value)
Writes a double element that has a prefix (3.14
).
Parameters:
Returns:
Throws:
writeEndElement
public 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:
Throws:
writeFloat
public XmlWriter writeFloat(float value)
Writes a float value.
Parameters:
Returns:
Throws:
writeFloatAttribute
public XmlWriter writeFloatAttribute(String localName, float value)
Writes a float attribute (attribute="2.7"
).
Parameters:
Returns:
Throws:
writeFloatAttribute
public XmlWriter writeFloatAttribute(String namespaceUri, String localName, float value)
Writes a float attribute that has a prefix (prefix:attribute="2.7"
).
Parameters:
Returns:
Throws:
writeFloatElement
public XmlWriter writeFloatElement(String localName, float value)
Writes a float element (2.7
).
Parameters:
Returns:
Throws:
writeFloatElement
public XmlWriter writeFloatElement(String namespaceUri, String localName, float value)
Writes a float element that has a prefix (2.7
).
Parameters:
Returns:
Throws:
writeInt
public XmlWriter writeInt(int value)
Writes an int value.
Parameters:
Returns:
Throws:
writeIntAttribute
public XmlWriter writeIntAttribute(String localName, int value)
Writes an int attribute (attribute="10"
).
Parameters:
Returns:
Throws:
writeIntAttribute
public XmlWriter writeIntAttribute(String namespaceUri, String localName, int value)
Writes an int attribute that has a prefix (prefix:attribute="10"
).
Parameters:
Returns:
Throws:
writeIntElement
public XmlWriter writeIntElement(String localName, int value)
Writes an int element (10
).
Parameters:
Returns:
Throws:
writeIntElement
public XmlWriter writeIntElement(String namespaceUri, String localName, int value)
Writes an int element that has a prefix (10
).
Parameters:
Returns:
Throws:
writeLong
public XmlWriter writeLong(long value)
Writes a long value.
Parameters:
Returns:
Throws:
writeLongAttribute
public XmlWriter writeLongAttribute(String namespaceUri, String localName, long value)
Writes a long attribute that has a prefix (prefix:attribute="100000000000"
).
Parameters:
Returns:
Throws:
writeLongAttribute
public XmlWriter writeLongAttribute(String localName, long value)
Writes a long attribute (attribute="100000000000"
).
Parameters:
Returns:
Throws:
writeLongElement
public XmlWriter writeLongElement(String namespaceUri, String localName, long value)
Writes a long element that has a prefix (100000000000
).
Parameters:
Returns:
Throws:
writeLongElement
public XmlWriter writeLongElement(String localName, long value)
Writes a long element (100000000000
).
Parameters:
Returns:
Throws:
writeNamespace
public XmlWriter writeNamespace(String namespaceUri)
Writes a default XML namespace.
Parameters:
Returns:
Throws:
writeNamespace
public 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:
Returns:
Throws:
writeNumber
public XmlWriter writeNumber(Number value)
Writes a nullable number.
If value
is null this is a no-op.
Parameters:
Returns:
Throws:
writeNumberAttribute
public XmlWriter writeNumberAttribute(String localName, Number value)
Writes a nullable number attribute (attribute="number"
).
Parameters:
Returns:
Throws:
writeNumberAttribute
public XmlWriter writeNumberAttribute(String namespaceUri, String localName, Number value)
Writes a nullable number attribute that has a prefix (prefix:attribute="number"
).
Parameters:
Returns:
Throws:
writeNumberElement
public XmlWriter writeNumberElement(String localName, Number value)
Writes a nullable number element (number
).
If the value
is null this is a no-op.
Parameters:
Returns:
Throws:
writeNumberElement
public 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:
Returns:
Throws:
writeStartDocument
public 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:
Throws:
writeStartDocument
public 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:
Returns:
Throws:
writeStartElement
public 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:
Returns:
Throws:
writeStartElement
public 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:
Returns:
Throws:
writeStartSelfClosingElement
public 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:
Returns:
Throws:
writeStartSelfClosingElement
public 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:
Returns:
Throws:
writeString
public 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:
Returns:
Throws:
writeStringAttribute
public XmlWriter writeStringAttribute(String localName, String value)
Writes a String attribute (attribute="value"
).
Parameters:
Returns:
Throws:
writeStringAttribute
public XmlWriter writeStringAttribute(String namespaceUri, String localName, String value)
Writes a String attribute that has a prefix (prefix:attribute="value"
).
Parameters:
Returns:
Throws:
writeStringElement
public XmlWriter writeStringElement(String localName, String value)
Writes a string element (string
).
If the value
is null this is a no-op.
Parameters:
Returns:
Throws:
writeStringElement
public 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:
Returns:
Throws:
writeXml
public XmlWriter writeXml(XmlSerializable value)
Writes an XmlSerializable<T> object.
If the value
is null this is a no-op.
Parameters:
Returns:
Throws:
writeXml
public 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:
Returns:
Throws:
Applies to
Azure SDK for Java