XML

class XML(val config: XmlConfig, serializersModule: SerializersModule = EmptySerializersModule()) : StringFormat(source)

Class that provides access to XML parsing and serialization for the Kotlin Serialization system. In most cases the companion functions would be used. Creating an object explicitly however allows for the serialization to be configured.

Note that at this point not all configuration options will work on all platforms.

The serialization can be configured with various annotations: XmlSerialName, XmlChildrenName, XmlPolyChildren, XmlDefault, XmlElement. These control the way the content is actually serialized. Those tags that support being set on types (rather than properties) prefer values set on properties (the property can override settings on the type).

Serialization normally prefers to store values as attributes. This can be overridden by the XmlElement annotation to force a tag child. Similarly XmlValue can be used for the child to be marked as textual content of the parent tag

  • only one such child is allowed.

Naming of tags and attributes follows some special rules. In particular attributes will be named based on their use where tags are named based on their type. Both can be overridden by specifying XmlSerialName on the property.

When names are not specified on types, their class name is used, but the package is normally omitted if it matches the package name of the class that represents the parent. Attributes get their use site name which is either the property name or the name modified through SerialName

Constructors

Link copied to clipboard
constructor(serializersModule: SerializersModule = EmptySerializersModule(), configure: XmlConfig.Builder.() -> Unit = {})
constructor(config: XmlConfig, serializersModule: SerializersModule = EmptySerializersModule())

Types

Link copied to clipboard
Link copied to clipboard
data class ParsedData<T>(val elementIndex: Int, val value: T, val unParsed: Boolean = false)

Class to support recovery in parsing.

Link copied to clipboard
interface XmlCodecConfig
Link copied to clipboard

An interface that allows custom serializers to special case being serialized to XML and retrieve the underlying XmlReader. This is used for example by CompactFragment to read arbitrary XML from the stream and store it inside the buffer (without attempting to use the serializer/decoder for it.

Link copied to clipboard

An interface that allows custom serializers to special case being serialized to XML and retrieve the underlying XmlWriter. This is used for example by CompactFragment to make the fragment transparent when serializing to XML.

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun copy(serializersModule: SerializersModule = this.serializersModule, configure: XmlConfig.Builder.() -> Unit): XML
Link copied to clipboard
inline fun <T : Any> decodeFromReader(reader: XmlReader, rootName: QName? = null): T
fun <T> decodeFromReader(deserializer: DeserializationStrategy<T>, reader: XmlReader, rootName: QName? = null): T

Parse an object of the type T out of the reader. This function is intended mostly to be used indirectly where though the reified function.

Link copied to clipboard
open override fun <T> decodeFromString(deserializer: DeserializationStrategy<T>, string: String): T
fun <T> decodeFromString(deserializer: DeserializationStrategy<T>, string: String, rootName: QName?): T

Decode the given string value using the deserializer. It is equivalent to decodeFromReader(deserializer, XmlStreaming.newReader(string)).

Link copied to clipboard
open override fun <T> encodeToString(serializer: SerializationStrategy<T>, value: T): String

fun <T> encodeToString(serializer: SerializationStrategy<T>, value: T, prefix: String?): String
fun <T> encodeToString(serializer: SerializationStrategy<T>, value: T, rootName: QName): String

Transform into a string. This function is expected to be called indirectly.

Link copied to clipboard
inline fun <T : Any> encodeToWriter(target: XmlWriter, value: T, prefix: String?)

Write the object to the given writer

fun <T> encodeToWriter(target: XmlWriter, serializer: SerializationStrategy<T>, value: T, prefix: String? = null)
fun <T> encodeToWriter(target: XmlWriter, serializer: SerializationStrategy<T>, value: T, rootName: QName?)

Transform onto an existing xml writer.

Link copied to clipboard
fun xmlDescriptor(deserializer: DeserializationStrategy<*>, rootName: QName? = null): XmlDescriptor
fun xmlDescriptor(deserializer: KSerializer<*>, rootName: QName? = null): XmlDescriptor
fun xmlDescriptor(serializer: SerializationStrategy<*>, rootName: QName? = null): XmlDescriptor