XmlWriter

interface XmlWriter : Closeable(source)

Interface representing the (wrapper) type that allows generating xml documents.

Inheritors

Properties

Link copied to clipboard
abstract val depth: Int

The current depth into the tree. The initial depth is 0

Link copied to clipboard
open var indent: Int

The indentation level to use for autoindenting the output

Link copied to clipboard
abstract var indentString: String

The indentation string to use for autoindenting the output

Link copied to clipboard

A namespace context that provides access to known namespaces/prefixes at this point in the writer.

Functions

Link copied to clipboard
abstract fun attribute(namespace: String?, name: String, prefix: String?, value: String)

Write an attribute.

Link copied to clipboard
abstract fun cdsect(text: String)

Write a CDATA section

Link copied to clipboard
abstract override fun close()

Close the writer. After invoking this the writer is not writable.

Link copied to clipboard
abstract fun comment(text: String)

Write a comment.

Link copied to clipboard
abstract fun docdecl(text: String)

Write a document declaration (DTD).

Link copied to clipboard
abstract fun endDocument()

Close the document. This will do checks, and update the state, but there is no actual content in an xml stream that corresponds to it.

Link copied to clipboard
abstract fun endTag(namespace: String?, localName: String, prefix: String?)

Write a closing tag.

Link copied to clipboard
fun XmlWriter.endTag(predelemname: QName)
Link copied to clipboard
abstract fun entityRef(text: String)

Write an entity reference

Link copied to clipboard
Link copied to clipboard
abstract fun flush()

Flush all state to the underlying buffer

Link copied to clipboard
abstract fun getNamespaceUri(prefix: String): String?

Get the namespace uri the prefix is currently bound to

Link copied to clipboard
abstract fun getPrefix(namespaceUri: String?): String?

Get a prefix the uri is currently bound to

Link copied to clipboard
abstract fun ignorableWhitespace(text: String)

Write ignorable whitespace.

Link copied to clipboard
open fun namespaceAttr(namespace: Namespace)
abstract fun namespaceAttr(namespacePrefix: String, namespaceUri: String)

Write a namespace declaration attribute.

Link copied to clipboard
abstract fun processingInstruction(text: String)

Write a processing instruction with the given raw content. When using, prefer the version taking two arguments

open fun processingInstruction(target: String, data: String)

Write a processing instruction with the given target and data

Link copied to clipboard

Serialize the content of the reader to the writer. This will continue until the reader has no more events. Note that this does not attempt to balance the tags. It will ignore star/end document events, processing instructions and document declarations if the writer has depth>0 (is in an element where such instructions are illegal).

Link copied to clipboard
abstract fun setPrefix(prefix: String, namespaceUri: String)

Bind the prefix to the given uri for this element.

Link copied to clipboard
inline fun XmlWriter.smartStartTag(qName: QName, body: XmlWriter.() -> Unit)

Enhanced function for writing start tags, that will attempt to reuse prefixes.

fun XmlWriter.smartStartTag(nsUri: String?, localName: String, prefix: String? = null): String

Enhanced function for writing start tags, that will attempt to reuse prefixes. Rather than use the passed prefix it will look up the prefix for the given namespace, and if present use that. It will also ensure to write the appropriate namespace attribute if needed. If the namespace is the default/null, xml or the xmlns namespace the implementation will be as expected.

inline fun XmlWriter.smartStartTag(nsUri: String?, localName: String, prefix: String? = null, body: XmlWriter.() -> Unit)

Helper function for writing tags that will automatically write the end tag. Otherwise

Link copied to clipboard
abstract fun startDocument(version: String? = null, encoding: String? = null, standalone: Boolean? = null)

Start the document. This causes an xml declaration to be generated with the relevant content.

Link copied to clipboard
abstract fun startTag(namespace: String?, localName: String, prefix: String?)

Write a start tag. This increases the current depth.

Link copied to clipboard
inline fun XmlWriter.startTag(nsUri: String?, localName: String, prefix: String? = null, body: XmlWriter.() -> Unit)
Link copied to clipboard
abstract fun text(text: String)

Write text.

Link copied to clipboard
fun XmlWriter.writeAttribute(name: String, value: Any?)
fun XmlWriter.writeAttribute(name: String, value: Long)
fun XmlWriter.writeAttribute(name: String, value: QName?)
fun XmlWriter.writeAttribute(name: QName, value: String?)
Link copied to clipboard

Write the current event to the writer. Note that for tags/start elements this will write the attributes, but not the children.

Link copied to clipboard
fun XmlWriter.writeElement(missingNamespaces: MutableMap<String, String>?, reader: XmlReader)

Write the entirety of an element content to the writer.

Link copied to clipboard
fun XmlWriter.writeElementContent(missingNamespaces: MutableMap<String, String>?, reader: XmlReader)

Write the child content of the current element in the reader to the output This does not write the container itself

Link copied to clipboard
inline fun <T> XmlWriter.writeListIfNotEmpty(iterable: Iterable<T>, nsUri: String?, localName: String, prefix: String? = null, body: XmlWriter.(T) -> Unit)

Helper function for writing a list only if it contains any element.

Link copied to clipboard
fun XmlWriter.writeSimpleElement(nsUri: String?, localName: String, prefix: String?, value: String?)