XMLCoder Documentation

Protocol Dynamic​Node​Decoding

public protocol DynamicNodeDecoding: Decodable  

Allows conforming types to specify how its properties will be decoded.

For example:

struct Book: Codable, Equatable, DynamicNodeDecoding {
    let id: UInt
    let title: String
    let categories: [Category]

    enum CodingKeys: String, CodingKey {
        case id
        case title
        case categories = "category"
    }

    static func nodeDecoding(for key: CodingKey) -> XMLDecoder.NodeDecoding {
        switch key {
        case Book.CodingKeys.id: return .attribute
        default: return .element
        }
    }
}

allows XML of this form to be decoded into values of type Book:

<book id="123">
    <title>Cat in the Hat</title>
    <category>Kids</category>
    <category>Wildlife</category>
</book>
%51 DynamicNodeDecoding DynamicNodeDecoding Decodable Decodable DynamicNodeDecoding->Decodable

Conforms To

Decodable

Requirements

node​Decoding(for:​)

static func nodeDecoding(for key: CodingKey) -> XMLDecoder.NodeDecoding