XMLCoder Documentation

Class XMLDecoder

open class XMLDecoder  

XMLDecoder facilitates the decoding of XML into semantic Decodable types.

Nested Types

XMLDecoder.DateDecodingStrategy

The strategy to use for decoding Date values.

XMLDecoder.DataDecodingStrategy

The strategy to use for decoding Data values.

XMLDecoder.NonConformingFloatDecodingStrategy

The strategy to use for non-XML-conforming floating-point values (IEEE 754 infinity and NaN).

XMLDecoder.KeyDecodingStrategy

The strategy to use for automatically changing the box of keys before decoding.

XMLDecoder.NodeDecoding

A node's decoding type

XMLDecoder.NodeDecodingStrategy

Set of strategies to use for encoding of nodes.

Initializers

init(trim​Value​Whitespaces:​remove​Whitespace​Elements:​)

public init(trimValueWhitespaces: Bool = true, removeWhitespaceElements: Bool = false)  

Initializes self with default strategies.

Properties

date​Decoding​Strategy

open var dateDecodingStrategy: DateDecodingStrategy = .secondsSince1970

The strategy to use in decoding dates. Defaults to .secondsSince1970.

data​Decoding​Strategy

open var dataDecodingStrategy: DataDecodingStrategy = .base64

The strategy to use in decoding binary data. Defaults to .base64.

non​Conforming​Float​Decoding​Strategy

open var nonConformingFloatDecodingStrategy: NonConformingFloatDecodingStrategy = .throw

The strategy to use in decoding non-conforming numbers. Defaults to .throw.

key​Decoding​Strategy

open var keyDecodingStrategy: KeyDecodingStrategy = .useDefaultKeys

The strategy to use for decoding keys. Defaults to .useDefaultKeys.

node​Decoding​Strategy

open var nodeDecodingStrategy: NodeDecodingStrategy = .deferredToDecoder

The strategy to use in encoding encoding attributes. Defaults to .deferredToEncoder.

user​Info

open var userInfo: [CodingUserInfoKey: Any] = [:] 

Contextual user-provided information for use during decoding.

error​Context​Length

open var errorContextLength: UInt = 0

The error context length. Non-zero length makes an error thrown from the XML parser with line/column location repackaged with a context around that location of specified length. For example, if an error was thrown indicating that there's an unexpected character at line 3, column 15 with errorContextLength set to 10, a new error type is rethrown containing 5 characters before column 15 and 5 characters after, all on line 3. Line wrapping should be handled correctly too as the context can span more than a few lines.

should​Process​Namespaces

open var shouldProcessNamespaces: Bool = false

A boolean value that determines whether the parser reports the namespaces and qualified names of elements. The default value is false.

trim​Value​Whitespaces

open var trimValueWhitespaces: Bool

A boolean value that determines whether the parser trims whitespaces and newlines from the end and the beginning of string values. The default value is true.

remove​Whitespace​Elements

open var removeWhitespaceElements: Bool

A boolean value that determines whether to remove pure whitespace elements that have sibling elements that aren't pure whitespace. The default value is false.

Methods

decode(_:​from:​)

open func decode<T: Decodable>(
        _ type: T.Type,
        from data: Data
    ) throws -> T  

Decodes a top-level box of the given type from the given XML representation.

Parameters

type T.​Type

The type of the box to decode.

data Data

The data to decode from.

Throws

An error if any box throws an error during decoding.

Returns

A box of the requested type.