Class
XMLDecoder
open class XMLDecoder
XMLDecoder
facilitates the decoding of XML into semantic Decodable
types.
Relationships
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(trimValueWhitespaces:removeWhitespaceElements:)
public init(trimValueWhitespaces: Bool = true, removeWhitespaceElements: Bool = false)
Initializes self
with default strategies.
Properties
dateDecodingStrategy
open var dateDecodingStrategy: DateDecodingStrategy = .secondsSince1970
The strategy to use in decoding dates. Defaults to .secondsSince1970
.
dataDecodingStrategy
open var dataDecodingStrategy: DataDecodingStrategy = .base64
The strategy to use in decoding binary data. Defaults to .base64
.
nonConformingFloatDecodingStrategy
open var nonConformingFloatDecodingStrategy: NonConformingFloatDecodingStrategy = .throw
The strategy to use in decoding non-conforming numbers. Defaults to .throw
.
keyDecodingStrategy
open var keyDecodingStrategy: KeyDecodingStrategy = .useDefaultKeys
The strategy to use for decoding keys. Defaults to .useDefaultKeys
.
nodeDecodingStrategy
open var nodeDecodingStrategy: NodeDecodingStrategy = .deferredToDecoder
The strategy to use in encoding encoding attributes. Defaults to .deferredToEncoder
.
userInfo
open var userInfo: [CodingUserInfoKey: Any] = [:]
Contextual user-provided information for use during decoding.
errorContextLength
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.
shouldProcessNamespaces
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
.
trimValueWhitespaces
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
.
removeWhitespaceElements
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
Name | Type | Description |
---|---|---|
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.