### XML Input Format
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeDecoding
Example XML structure compatible with the provided Book model implementation.
```xml
Cat in the Hat
Kids
Wildlife
```
--------------------------------
### XML Output Example
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeEncoding
The resulting XML structure produced by the Book struct implementation.
```xml
123
Cat in the Hat
Kids
Wildlife
```
--------------------------------
### Initialize XMLEncoder with Default Strategies
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Initializes the XMLEncoder with default strategies. No specific setup is required beyond instantiation.
```swift
public init()
```
--------------------------------
### Implement DynamicNodeEncoding for a Struct
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeEncoding
Example implementation of a Book struct conforming to DynamicNodeEncoding to customize XML output.
```swift
struct Book: Codable, Equatable, DynamicNodeEncoding {
let id: UInt
let title: String
let categories: [Category]
enum CodingKeys: String, CodingKey {
case id
case title
case categories = "category"
}
static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding {
switch key {
case Book.CodingKeys.id: return .both
default: return .element
}
}
}
```
--------------------------------
### Example Usage of ElementAndAttribute
Source: https://coreoffice.github.io/XMLCoder/ElementAndAttribute
Demonstrates encoding and decoding a Book struct with an ElementAndAttribute property.
```swift
struct Book: Codable {
@ElementAndAttribute var id: Int
}
```
--------------------------------
### Implement DynamicNodeDecoding for a Model
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeDecoding
Example implementation of a struct conforming to DynamicNodeDecoding to map specific keys to XML attributes.
```swift
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
}
}
}
```
--------------------------------
### Declare XMLDocumentType Structure
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType
Defines the basic structure for XMLDocumentType. No specific setup is required.
```swift
public struct XMLDocumentType
```
--------------------------------
### Encode/Decode Book with ID Attribute
Source: https://coreoffice.github.io/XMLCoder/Attribute
This example shows how a Book struct with an @Attribute property is encoded to XML with an attribute and decoded from XML with an attribute.
```swift
struct Book: Codable {
@Attribute var id: Int
}
```
--------------------------------
### Use Element Property Wrapper in Codable Struct
Source: https://coreoffice.github.io/XMLCoder/Element
Example of applying the @Element wrapper to a property within a Codable struct.
```swift
struct Book: Codable {
@Element var id: Int
}
```
--------------------------------
### Define Union-Type Enum
Source: https://coreoffice.github.io/XMLCoder/XMLChoiceCodingKey
An example enum type that can hold either an Int or a String.
```swift
enum IntOrString {
case int(Int)
case string(String)
}
```
--------------------------------
### Define Attribute Property Wrapper
Source: https://coreoffice.github.io/XMLCoder/Attribute
Use this property wrapper to specify that a property should be encoded and decoded as an XML attribute. For example, a Book struct with an 'id' attribute.
```swift
@propertyWrapper
public struct Attribute: XMLAttributeProtocol
```
--------------------------------
### Initialize OutputFormatting
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_OutputFormatting
Creates an instance of OutputFormatting using a raw integer value.
```swift
public init(rawValue: UInt)
```
--------------------------------
### Initialize XMLHeader
Source: https://coreoffice.github.io/XMLCoder/XMLHeader
Constructor for creating an XMLHeader instance with optional version, encoding, and standalone attributes.
```swift
public init(version: Double? = nil, encoding: String? = nil, standalone: String? = nil)
```
--------------------------------
### Initialize Element
Source: https://coreoffice.github.io/XMLCoder/Element
Initializer for the Element property wrapper.
```swift
public init(_ wrappedValue: Value)
```
--------------------------------
### Initialize XMLDecoder
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder
Creates a new instance with optional whitespace handling configurations.
```swift
public init(trimValueWhitespaces: Bool = true, removeWhitespaceElements: Bool = false)
```
--------------------------------
### Use Default Keys Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_KeyDecodingStrategy
The default strategy that uses keys exactly as specified by the type.
```swift
case useDefaultKeys
```
--------------------------------
### Configure Pretty Printed Output
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_OutputFormatting
Enables human-readable XML with indentation.
```swift
public static let prettyPrinted
```
--------------------------------
### Set User Info for Encoding
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Provides a dictionary for contextual user-provided information that can be used during the encoding process.
```swift
open var userInfo: [CodingUserInfoKey: Any] = [:]
```
--------------------------------
### Define OutputFormatting Structure
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_OutputFormatting
The base structure for configuring XML output formatting.
```swift
public struct OutputFormatting: OptionSet
```
--------------------------------
### XMLDecoder Initialization
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder
Initializes a new instance of the XMLDecoder with specific whitespace handling configurations.
```APIDOC
## init(trimValueWhitespaces:removeWhitespaceElements:)
### Description
Initializes the XMLDecoder with default strategies and whitespace configuration.
### Parameters
#### Request Body
- **trimValueWhitespaces** (Bool) - Optional - Determines whether to trim whitespaces and newlines from string values. Defaults to true.
- **removeWhitespaceElements** (Bool) - Optional - Determines whether to remove pure whitespace elements that have non-whitespace siblings. Defaults to false.
```
--------------------------------
### Set Output Formatting
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Sets the output format for the XML data. Defaults to an empty set, meaning no specific formatting is applied by default.
```swift
open var outputFormatting: OutputFormatting = []
```
--------------------------------
### Configure decoding context and behavior
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder
Properties for managing user info, error reporting, namespace processing, and whitespace trimming.
```swift
open var userInfo: [CodingUserInfoKey: Any] = [:]
```
```swift
open var errorContextLength: UInt = 0
```
```swift
open var shouldProcessNamespaces: Bool = false
```
```swift
open var trimValueWhitespaces: Bool
```
```swift
open var removeWhitespaceElements: Bool
```
--------------------------------
### Configure Sorted Keys
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_OutputFormatting
Enables lexicographic sorting of XML keys.
```swift
public static let sortedKeys
```
--------------------------------
### Configure No Empty Elements
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_OutputFormatting
Forces full element tags instead of self-closing or shorthand notation for empty elements.
```swift
public static let noEmptyElements
```
--------------------------------
### Configure decoding strategies
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder
Properties for customizing how specific data types and keys are handled during the decoding process.
```swift
open var dateDecodingStrategy: DateDecodingStrategy = .secondsSince1970
```
```swift
open var dataDecodingStrategy: DataDecodingStrategy = .base64
```
```swift
open var nonConformingFloatDecodingStrategy: NonConformingFloatDecodingStrategy = .throw
```
```swift
open var keyDecodingStrategy: KeyDecodingStrategy = .useDefaultKeys
```
```swift
open var nodeDecodingStrategy: NodeDecodingStrategy = .deferredToDecoder
```
--------------------------------
### Convert to Kebab Case Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_KeyEncodingStrategy
Converts camelCase keys to kebab-case by inserting hyphens at word boundaries.
```swift
case convertToKebabCase
```
--------------------------------
### Convert From Kebab Case Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_KeyDecodingStrategy
Converts kebab-case keys to camelCase keys.
```swift
case convertFromKebabCase
```
--------------------------------
### String Encoding Strategy: deferredToString
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_StringEncodingStrategy
Uses the default String encoding strategy. This is the default behavior.
```swift
case deferredToString
```
--------------------------------
### ConvertFromString Strategy Case
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NonConformingFloatDecodingStrategy
Strategy to decode non-conforming values from specified string representations.
```swift
case convertFromString(positiveInfinity: String, negativeInfinity: String, nan: String)
```
--------------------------------
### Initialize Attribute Property Wrapper
Source: https://coreoffice.github.io/XMLCoder/Attribute
Initializes the Attribute property wrapper with a wrapped value.
```swift
public init(_ wrappedValue: Value)
```
--------------------------------
### Uppercased Key Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_KeyEncodingStrategy
Converts all letters in the key to uppercase.
```swift
case uppercased
```
--------------------------------
### Set Key Encoding Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Defines the strategy for automatically changing the value of keys before encoding. Defaults to `.useDefaultKeys`.
```swift
open var keyEncodingStrategy: KeyEncodingStrategy = .useDefaultKeys
```
--------------------------------
### Create System XMLDocumentType
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType
Constructs an XMLDocumentType using a system DTD declaration. Requires root element and DTD location.
```swift
public static func system(rootElement: String, dtdLocation: String) -> XMLDocumentType
```
--------------------------------
### Define KeyEncodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_KeyEncodingStrategy
The base enumeration definition for key encoding strategies.
```swift
public enum KeyEncodingStrategy
```
--------------------------------
### Convert From Uppercase Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_KeyDecodingStrategy
Converts uppercase keys to camelCase.
```swift
case convertFromUppercase
```
--------------------------------
### Set Data Encoding Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Determines the strategy used for encoding binary Data values. The default strategy is `.base64`.
```swift
open var dataEncodingStrategy: DataEncodingStrategy = .base64
```
--------------------------------
### Implement Initializer for XMLDecodableSequence
Source: https://coreoffice.github.io/XMLCoder/XMLDecodableSequence
The required initializer for the XMLDecodableSequence protocol. Ensure your custom sequence type conforms to this.
```swift
init()
```
--------------------------------
### Lowercased Key Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_KeyEncodingStrategy
Converts all letters in the key to lowercase.
```swift
case lowercased
```
--------------------------------
### Set String Encoding Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Specifies the strategy for encoding String values. Defaults to `.deferredToString`.
```swift
open var stringEncodingStrategy: StringEncodingStrategy = .deferredToString
```
--------------------------------
### ElementAndAttribute Initializer
Source: https://coreoffice.github.io/XMLCoder/ElementAndAttribute
Initializes the ElementAndAttribute property wrapper with a wrapped value.
```swift
public init(_ wrappedValue: Value)
```
--------------------------------
### Convert From Capitalized Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_KeyDecodingStrategy
Converts capitalized keys to camelCase.
```swift
case convertFromCapitalized
```
--------------------------------
### Throw Strategy Case
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NonConformingFloatEncodingStrategy
The default strategy that throws an error when encountering non-conforming values.
```swift
case `throw`
```
--------------------------------
### Access XMLHeader properties
Source: https://coreoffice.github.io/XMLCoder/XMLHeader
Properties representing the XML header attributes.
```swift
public let version: Double?
```
```swift
public let encoding: String?
```
```swift
public let standalone: String?
```
--------------------------------
### Convert to Snake Case Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_KeyEncodingStrategy
Converts camelCase keys to snake_case by inserting underscores at word boundaries.
```swift
case convertToSnakeCase
```
--------------------------------
### Custom Strategy Case
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NodeDecodingStrategy
A strategy that uses a closure to compute node decoding based on the type and coding key.
```swift
case custom((Decodable.Type, Decoder) -> ((CodingKey) -> NodeDecoding))
```
--------------------------------
### Custom Strategy Case
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NodeEncodingStrategy
Allows providing a custom closure to compute the node encoding based on the coding key.
```swift
case custom(XMLEncodingClosure)
```
--------------------------------
### ConvertToString Strategy Case
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NonConformingFloatEncodingStrategy
Encodes non-conforming values using custom string representations for positive infinity, negative infinity, and NaN.
```swift
case convertToString(positiveInfinity: String, negativeInfinity: String, nan: String)
```
--------------------------------
### DataEncodingStrategy Cases
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DataEncodingStrategy
Available cases for configuring how Data is handled during encoding.
```swift
case deferredToData
```
```swift
case base64
```
```swift
case custom((Data, Encoder) throws -> ())
```
--------------------------------
### XMLCoder OutputFormatting
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_OutputFormatting
The `OutputFormatting` struct allows you to configure the presentation of your encoded XML data. You can enable pretty-printing, sort keys, and control the representation of empty elements.
```APIDOC
## Structure `XMLEncoder.OutputFormatting`
### Description
The formatting of the output XML data.
### Member Of
- `XMLEncoder`
### Conforms To
- `OptionSet`
## Initializers
### `init(rawValue:)`
Creates an `OutputFormatting` value with the given raw value.
### Properties
#### `rawValue`
The format's default value.
#### `prettyPrinted`
Produce human-readable XML with indented output.
#### `sortedKeys`
Produce XML with keys sorted in lexicographic order.
#### `noEmptyElements`
Produce XML with no short-hand annotation for empty elements, e.g., use `` over `
`
```
--------------------------------
### Custom Key Decoding Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_KeyDecodingStrategy
Provides a custom closure to transform keys based on the current coding path.
```swift
case custom((_ codingPath: [CodingKey]) -> CodingKey)
```
--------------------------------
### Retroactively Conform CodingKeys
Source: https://coreoffice.github.io/XMLCoder/XMLChoiceCodingKey
Conform the CodingKeys enum to XMLChoiceCodingKey for XML targeting.
```swift
extension IntOrString.CodingKeys: XMLChoiceCodingKey {}
```
--------------------------------
### Set Date Encoding Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Determines the strategy used for encoding Date values. The default strategy is `.deferredToDate`.
```swift
open var dateEncodingStrategy: DateEncodingStrategy = .deferredToDate
```
--------------------------------
### Define KeyDecodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_KeyDecodingStrategy
The enumeration used to specify key transformation strategies.
```swift
public enum KeyDecodingStrategy
```
--------------------------------
### Set Pretty Print Indentation
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Specifies the indentation to use when the XML is pretty-printed. The default indentation is set to 4 spaces.
```swift
open var prettyPrintIndentation: PrettyPrintIndentation
```
--------------------------------
### Convert From Snake Case Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_KeyDecodingStrategy
Converts snake_case keys to camelCase keys using the ICU root locale.
```swift
case convertFromSnakeCase
```
--------------------------------
### DataDecodingStrategy Cases
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_DataDecodingStrategy
Available cases for the DataDecodingStrategy enumeration.
```swift
case deferredToData
```
```swift
case base64
```
```swift
case custom((_ decoder: Decoder) throws -> Data)
```
--------------------------------
### Encode Value with Root Key, Attributes, Header, and Doctype
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Encodes a top-level Encodable value into its XML representation. Allows specifying a root key, root attributes, an XML header, and a document type definition. Throws an error if encoding fails.
```swift
open func encode(_ value: T,
withRootKey rootKey: String? = nil,
rootAttributes: [String: String]? = nil,
header: XMLHeader? = nil,
doctype: XMLDocumentType? = nil) throws -> Data
```
--------------------------------
### System External Type Case
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType_External
Represents the 'SYSTEM' external type for XML documents. This case conforms to the String type.
```swift
case system = "SYSTEM"
```
--------------------------------
### XMLEncoder.KeyEncodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_KeyEncodingStrategy
The strategy to use for automatically changing the value of keys before encoding.
```APIDOC
## Enumeration `XMLEncoder.KeyEncodingStrategy`
### Description
The strategy to use for automatically changing the value of keys before encoding.
### Member Of
- `XMLEncoder`
### Enumeration Cases
#### `useDefaultKeys`
##### Description
Use the keys specified by each type. This is the default strategy.
#### `convertToSnakeCase`
##### Description
Convert from "camelCaseKeys" to "snake_case_keys" before writing a key to XML payload. Capital characters are determined by testing membership in `CharacterSet.uppercaseLetters` and `CharacterSet.lowercaseLetters` (Unicode General Categories Lu and Lt). The conversion to lower case uses `Locale.system`, also known as the ICU "root" locale. This means the result is consistent regardless of the current user's locale and language preferences.
Converting from camel case to snake case:
1. Splits words at the boundary of lower-case to upper-case
2. Inserts `_` between words
3. Lowercases the entire string
4. Preserves starting and ending `_`.
For example, `oneTwoThree` becomes `one_two_three`. `_oneTwoThree_` becomes `_one_two_three_`.
#### `convertToKebabCase`
##### Description
Same as convertToSnakeCase, but using `-` instead of `_` For example, `oneTwoThree` becomes `one-two-three`.
#### `capitalized`
##### Description
Capitalize the first letter only `oneTwoThree` becomes `OneTwoThree`
#### `uppercased`
##### Description
Uppercase ize all letters `oneTwoThree` becomes `ONETWOTHREE`
#### `lowercased`
##### Description
Lowercase all letters `oneTwoThree` becomes `onetwothree`
#### `custom`
##### Description
Provide a custom conversion to the key in the encoded XML from the keys specified by the encoded types. The full path to the current encoding position is provided for context (in case you need to locate this key within the payload). The returned key is used in place of the last component in the coding path before encoding. If the result of the conversion is a duplicate key, then only one value will be present in the result.
```
--------------------------------
### Capitalized Key Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_KeyEncodingStrategy
Capitalizes the first letter of the key.
```swift
case capitalized
```
--------------------------------
### XMLDocumentType Factory Methods
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType
Methods for creating instances of XMLDocumentType.
```APIDOC
## XMLDocumentType Factory Methods
### Description
Provides static methods to construct `XMLDocumentType` instances.
### Methods
#### `public(rootElement:dtdName:dtdLocation:)`
Creates a public XML document type.
- **rootElement** (String) - Required - The name of the root element.
- **dtdName** (String) - Required - The name of the DTD.
- **dtdLocation** (String) - Required - The location of the DTD.
#### `system(rootElement:dtdLocation:)`
Creates a system XML document type.
- **rootElement** (String) - Required - The name of the root element.
- **dtdLocation** (String) - Required - The location of the DTD.
```
--------------------------------
### Define DynamicNodeDecoding Protocol
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeDecoding
The base protocol definition for types that require custom XML node decoding logic.
```swift
public protocol DynamicNodeDecoding: Decodable
```
--------------------------------
### Implement Codable with XMLChoiceCodingKey
Source: https://coreoffice.github.io/XMLCoder/XMLChoiceCodingKey
Implementation of Codable for the union-type enum using XMLChoiceCodingKey.
```swift
extension IntOrString: Codable {
enum CodingKeys: String, XMLChoiceCodingKey {
case int
case string
}
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case let .int(value):
try container.encode(value, forKey: .int)
case let .string(value):
try container.encode(value, forKey: .string)
}
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
do {
self = .int(try container.decode(Int.self, forKey: .int))
} catch {
self = .string(try container.decode(String.self, forKey: .string))
}
}
}
```
--------------------------------
### DynamicNodeDecoding Protocol
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeDecoding
Defines the requirements for conforming types to specify node decoding strategies.
```APIDOC
## Protocol DynamicNodeDecoding
### Description
Allows conforming types to specify how its properties will be decoded from XML.
### Requirements
- **nodeDecoding(for:)** (static func) - Returns an XMLDecoder.NodeDecoding strategy for a given CodingKey.
### Conforms To
- Decodable
### Implementation Example
```swift
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
}
}
}
```
```
--------------------------------
### Node Encoding Method Signature
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeEncoding
The required method signature for defining node encoding behavior.
```swift
static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding
```
--------------------------------
### Set Non-Conforming Float Encoding Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Specifies the strategy for encoding non-XML-conforming floating-point values like infinity and NaN. Defaults to `.throw`.
```swift
open var nonConformingFloatEncodingStrategy: NonConformingFloatEncodingStrategy = .throw
```
--------------------------------
### Access RawValue Property
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_OutputFormatting
Retrieves the underlying raw value of the formatting option.
```swift
public let rawValue: UInt
```
--------------------------------
### nodeEncoding(for:)
Source: https://coreoffice.github.io/XMLCoder/Array
Defines the node encoding configuration for a specific coding key within an Array context.
```APIDOC
## nodeEncoding(for:)
### Description
Returns the XMLEncoder.NodeEncoding configuration for a given CodingKey.
### Method
static func
### Parameters
#### Parameters
- **key** (CodingKey) - Required - The coding key to retrieve the node encoding for.
### Response
- **XMLEncoder.NodeEncoding** - The encoding configuration associated with the provided key.
```
--------------------------------
### Create Public XMLDocumentType
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType
Constructs an XMLDocumentType using the public DTD declaration. Requires root element, DTD name, and DTD location.
```swift
public static func `public`(rootElement: String, dtdName: String, dtdLocation: String) -> XMLDocumentType
```
--------------------------------
### DeferredToDecoder Strategy Case
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NodeDecodingStrategy
The default strategy that defers decoding logic to the decoder.
```swift
case deferredToDecoder
```
--------------------------------
### String Encoding Strategy: cdata
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_StringEncodingStrategy
Encodes the String value as a CData-encoded string.
```swift
case cdata
```
--------------------------------
### DateDecodingStrategy Cases
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_DateDecodingStrategy
Individual cases for configuring how dates are decoded from XML.
```swift
case deferredToDate
```
```swift
case secondsSince1970
```
```swift
case millisecondsSince1970
```
```swift
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
case iso8601
```
```swift
case formatted(DateFormatter)
```
```swift
case custom((_ decoder: Decoder) throws -> Date)
```
--------------------------------
### Define Element Property Wrapper
Source: https://coreoffice.github.io/XMLCoder/Element
Declaration of the Element property wrapper conforming to XMLElementProtocol.
```swift
@propertyWrapper
public struct Element: XMLElementProtocol
```
--------------------------------
### XMLDecoder KeyDecodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_KeyDecodingStrategy
The KeyDecodingStrategy enumeration allows you to specify how keys in the XML data should be transformed before matching them with the keys in your Swift types during decoding.
```APIDOC
## Enumeration `XMLDecoder.KeyDecodingStrategy`
```swift
public enum KeyDecodingStrategy
```
The strategy to use for automatically changing the box of keys before decoding.
### Member Of
- `XMLDecoder`
`XMLDecoder` facilitates the decoding of XML into semantic `Decodable` types.
### Enumeration Cases
#### `useDefaultKeys`
```swift
case useDefaultKeys
```
Use the keys specified by each type. This is the default strategy.
#### `convertFromSnakeCase`
```swift
case convertFromSnakeCase
```
Convert from "snake_case_keys" to "camelCaseKeys" before attempting to match a key with the one specified by each type.
The conversion to upper case uses `Locale.system`, also known as the ICU "root" locale. This means the result is consistent regardless of the current user's locale and language preferences.
Converting from snake case to camel case:
1. Capitalizes the word starting after each `_`
2. Removes all `_`
3. Preserves starting and ending `_` (as these are often used to indicate private variables or other metadata). For example, `one_two_three` becomes `oneTwoThree`. `_one_two_three_` becomes `_oneTwoThree_`.
Using a key decoding strategy has a nominal performance cost, as each string key has to be inspected for the `_` character.
#### `convertFromKebabCase`
```swift
case convertFromKebabCase
```
Convert from "kebab-case" to "kebabCase" before attempting to match a key with the one specified by each type.
#### `convertFromCapitalized`
```swift
case convertFromCapitalized
```
Convert from "CodingKey" to "codingKey"
#### `convertFromUppercase`
```swift
case convertFromUppercase
```
Convert from "CODING_KEY" to "codingKey"
#### `custom`
```swift
case custom((_ codingPath: [CodingKey]) -> CodingKey)
```
Provide a custom conversion from the key in the encoded XML to the keys specified by the decoded types. The full path to the current decoding position is provided for context (in case you need to locate this key within the payload). The returned key is used in place of the last component in the coding path before decoding. If the result of the conversion is a duplicate key, then only one box will be present in the container for the type to decode from.
```
--------------------------------
### PrettyPrintIndentation Case: Spaces
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_PrettyPrintIndentation
Represents indentation using a specified number of spaces. Use when space-based indentation is preferred.
```swift
case spaces(Int)
```
--------------------------------
### Define XMLChoiceCodingKey Protocol
Source: https://coreoffice.github.io/XMLCoder/XMLChoiceCodingKey
The protocol definition for XMLChoiceCodingKey.
```swift
public protocol XMLChoiceCodingKey: CodingKey
```
--------------------------------
### Define DynamicNodeEncoding Protocol
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeEncoding
The base protocol definition for types that support dynamic node encoding.
```swift
public protocol DynamicNodeEncoding: Encodable
```
--------------------------------
### DateEncodingStrategy: deferredToDate
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DateEncodingStrategy
Defer to Date for choosing an encoding. This is the default strategy for encoding Date values.
```swift
case deferredToDate
```
--------------------------------
### decode(_:from:)
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder
Decodes a top-level object of a given type from XML data.
```APIDOC
## decode(_:from:)
### Description
Decodes a top-level box of the given type from the provided XML data.
### Parameters
#### Request Body
- **type** (T.Type) - Required - The type of the object to decode.
- **data** (Data) - Required - The XML data to decode from.
### Response
#### Success Response (200)
- **T** (Decodable) - An instance of the requested type.
```
--------------------------------
### DeferredToEncoder Strategy Case
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NodeEncodingStrategy
Default strategy that defers the encoding decision to the Encoder.
```swift
case deferredToEncoder
```
--------------------------------
### Decode Node as Element or Attribute
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NodeDecoding
Allows decoding from either elements or attributes, with elements taking precedence. This provides flexibility when dealing with XML that might use both forms.
```swift
case elementOrAttribute
```
--------------------------------
### PrettyPrintIndentation Case: Tabs
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_PrettyPrintIndentation
Represents indentation using a specified number of tabs. Use when tab-based indentation is preferred.
```swift
case tabs(Int)
```
--------------------------------
### Set Node Encoding Strategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Determines the strategy used for encoding nodes, such as attributes. Defaults to `.deferredToEncoder`.
```swift
open var nodeEncodingStrategy: NodeEncodingStrategy = .deferredToEncoder
```
--------------------------------
### Define NodeDecodingStrategy Enumeration
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NodeDecodingStrategy
The base enumeration definition for node decoding strategies.
```swift
public enum NodeDecodingStrategy
```
--------------------------------
### DateEncodingStrategy: formatted
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DateEncodingStrategy
Encode the Date as a string using a provided DateFormatter. Ensure the DateFormatter is configured correctly before use.
```swift
case formatted(DateFormatter)
```
--------------------------------
### Define DataDecodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_DataDecodingStrategy
The enumeration definition for DataDecodingStrategy.
```swift
public enum DataDecodingStrategy
```
--------------------------------
### XMLDocumentType Root Element Property
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType
Represents the root element of the XML document. This property is a constant string.
```swift
public let rootElement: String
```
--------------------------------
### Decode Node as Element
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NodeDecoding
Specifies that a node should be decoded from XML elements. This is the standard way to decode nested XML structures.
```swift
case element
```
--------------------------------
### Protocol DynamicNodeEncoding
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeEncoding
Defines the requirements for types that need custom XML node encoding behavior.
```APIDOC
## Protocol DynamicNodeEncoding
### Description
Allows conforming types to specify how their properties will be encoded into XML elements or attributes.
### Requirements
- **nodeEncoding(for:)** (static function) - Required - Returns an XMLEncoder.NodeEncoding value for a given CodingKey.
### Implementation Example
```swift
struct Book: Codable, Equatable, DynamicNodeEncoding {
let id: UInt
let title: String
let categories: [Category]
enum CodingKeys: String, CodingKey {
case id
case title
case categories = "category"
}
static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding {
switch key {
case Book.CodingKeys.id: return .both
default: return .element
}
}
}
```
```
--------------------------------
### Define ElementAndAttribute Property Wrapper
Source: https://coreoffice.github.io/XMLCoder/ElementAndAttribute
Defines the ElementAndAttribute property wrapper for XML decoding and encoding.
```swift
@propertyWrapper
public struct ElementAndAttribute: XMLElementAndAttributeProtocol
```
--------------------------------
### Enumeration `NodeEncoding`
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NodeEncoding
Details the NodeEncoding enumeration, its purpose, and its members.
```APIDOC
## Enumeration `NodeEncoding`
### Description
A node's encoding type. Specifies how a node will be encoded.
### Member Of
`XMLEncoder`
`XMLEncoder` facilitates the encoding of `Encodable` values into XML.
### Enumeration Cases
#### `attribute`
```swift
case attribute
```
#### `element`
```swift
case element
```
#### `both`
```swift
case both
```
### Properties
#### `default`
```swift
public static let `default`: NodeEncoding = .element
```
```
--------------------------------
### Define String Encoding Strategy Enum
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_StringEncodingStrategy
Defines the enumeration for string encoding strategies. This is the default strategy for XMLEncoder.
```swift
public enum StringEncodingStrategy
```
--------------------------------
### Public External Type Case
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType_External
Represents the 'PUBLIC' external type for XML documents. This case conforms to the String type.
```swift
case `public` = "PUBLIC"
```
--------------------------------
### DateEncodingStrategy: secondsSince1970
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DateEncodingStrategy
Encode the Date as a UNIX timestamp, represented as an XML number.
```swift
case secondsSince1970
```
--------------------------------
### Define DataEncodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DataEncodingStrategy
The enumeration definition for Data encoding strategies.
```swift
public enum DataEncodingStrategy
```
--------------------------------
### DateEncodingStrategy: custom
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DateEncodingStrategy
Encode the Date using a custom closure. If the closure fails, an empty automatic container is encoded instead. This provides maximum flexibility for date encoding.
```swift
case custom((Date, Encoder) throws -> ())
```
--------------------------------
### Enumeration DataEncodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DataEncodingStrategy
The strategy to use for encoding Data values.
```APIDOC
## Enumeration `DataEncodingStrategy`
### Description
The strategy to use for encoding `Data` values.
### Member Of
`XMLEncoder`
### Enumeration Cases
#### `deferredToData`
```swift
case deferredToData
```
Defer to `Data` for choosing an encoding.
#### `base64`
```swift
case base64
```
Encoded the `Data` as a Base64-encoded string. This is the default strategy.
#### `custom`
```swift
case custom((Data, Encoder) throws -> ())
```
Encode the `Data` as a custom value encoded by the given closure. If the closure fails to encode a value into the given encoder, the encoder will encode an empty automatic container in its place.
```
--------------------------------
### Define NodeEncodingStrategy Enumeration
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NodeEncodingStrategy
The base enumeration definition for node encoding strategies.
```swift
public enum NodeEncodingStrategy
```
--------------------------------
### Define XMLHeader structure
Source: https://coreoffice.github.io/XMLCoder/XMLHeader
The structure used to override XML header values during the encoding process.
```swift
public struct XMLHeader
```
--------------------------------
### Define DateDecodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_DateDecodingStrategy
The base enumeration definition for date decoding strategies.
```swift
public enum DateDecodingStrategy
```
--------------------------------
### Enumeration `XMLEncoder.NodeEncodingStrategy`
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NodeEncodingStrategy
Set of strategies to use for encoding of nodes. This enumeration is a member of XMLEncoder.
```APIDOC
## Enumeration `XMLEncoder.NodeEncodingStrategy`
### Description
Set of strategies to use for encoding of nodes.
### Member Of
`XMLEncoder`
### Enumeration Cases
#### `deferredToEncoder`
Defer to `Encoder` for choosing an encoding. This is the default strategy.
#### `custom`
Return a closure computing the desired node encoding for the value by its coding key.
```
--------------------------------
### XMLDocumentType Structure
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType
Details about the XMLDocumentType structure, including its properties and nested types.
```APIDOC
## XMLDocumentType Structure
### Description
Represents an XML document type declaration.
### Properties
- **rootElement** (String) - The name of the root element.
- **external** (External) - Information about external entities.
- **dtdName** (String?) - The name of the DTD.
- **dtdLocation** (String) - The location of the DTD.
### Nested Types
- **XMLDocumentType.External**
```
--------------------------------
### XMLDecoder.NonConformingFloatDecodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NonConformingFloatDecodingStrategy
The strategy to use for non-XML-conforming floating-point values (IEEE 754 infinity and NaN).
```APIDOC
## Enumeration `XMLDecoder.NonConformingFloatDecodingStrategy`
### Description
The strategy to use for non-XML-conforming floating-point values (IEEE 754 infinity and NaN).
### Member Of
`XMLDecoder`
`XMLDecoder` facilitates the decoding of XML into semantic `Decodable` types.
### Enumeration Cases
#### `throw`
##### Description
Throw upon encountering non-conforming values. This is the default strategy.
##### Code
```swift
case `throw`
```
#### `convertFromString`
##### Description
Decode the values from the given representation strings.
##### Parameters
- **positiveInfinity** (String) - Required - The string representation for positive infinity.
- **negativeInfinity** (String) - Required - The string representation for negative infinity.
- **nan** (String) - Required - The string representation for NaN (Not a Number).
##### Code
```swift
case convertFromString(positiveInfinity: String, negativeInfinity: String, nan: String)
```
```
--------------------------------
### Define XMLDecoder class
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder
The base class definition for XML decoding.
```swift
open class XMLDecoder
```
--------------------------------
### NodeEncoding Case: both
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NodeEncoding
Represents the encoding type where a node is encoded as both an attribute and an element.
```swift
case both
```
--------------------------------
### DateEncodingStrategy: iso8601
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DateEncodingStrategy
Encode the Date as an ISO-8601-formatted string, conforming to RFC 3339. Requires macOS 10.12, iOS 10.0, watchOS 3.0, or tvOS 10.0.
```swift
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
case iso8601
```
--------------------------------
### Declare XMLDecodableSequence Protocol
Source: https://coreoffice.github.io/XMLCoder/XMLDecodableSequence
Defines the XMLDecodableSequence protocol. Use this if your custom sequence type is not decoded correctly. Default conformances for Array and Dictionary are provided.
```swift
public protocol XMLDecodableSequence
```
--------------------------------
### Element Property Wrapper
Source: https://coreoffice.github.io/XMLCoder/Element
The Element property wrapper specifies that a property should be encoded and decoded as an XML element.
```APIDOC
## Element Property Wrapper
### Description
A property wrapper that specifies a given property should be encoded and decoded as an XML element.
### Declaration
`@propertyWrapper public struct Element: XMLElementProtocol`
### Usage Example
```swift
struct Book: Codable {
@Element var id: Int
}
// Encodes Book(id: 42) as 42
```
### Initializers
- **init(_ wrappedValue: Value)** - Initializes the element with the provided wrapped value.
### Properties
- **wrappedValue** (Value) - The underlying value being wrapped.
```
--------------------------------
### XMLChoiceCodingKey Protocol
Source: https://coreoffice.github.io/XMLCoder/XMLChoiceCodingKey
The XMLChoiceCodingKey protocol is used to resolve ambiguities between nested unkeyed container elements and choice elements in XML.
```APIDOC
## Protocol XMLChoiceCodingKey
### Description
An empty marker protocol that must be used when attempting to encode and decode union-type-like enums with associated values to and from XML choice elements.
### Conforms To
- CodingKey
### Usage
To use, conform your custom CodingKey enum to XMLChoiceCodingKey:
```swift
enum CodingKeys: String, XMLChoiceCodingKey {
case int
case string
}
```
Alternatively, retroactively conform the enum:
```swift
extension IntOrString.CodingKeys: XMLChoiceCodingKey {}
```
```
--------------------------------
### XMLDocumentType DTD Location Property
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType
A string representing the location of the Document Type Definition (DTD).
```swift
public let dtdLocation: String
```
--------------------------------
### XMLDocumentType DTD Name Property
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType
An optional string representing the name of the Document Type Definition (DTD).
```swift
public let dtdName: String?
```
--------------------------------
### Define PrettyPrintIndentation Enum
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_PrettyPrintIndentation
Defines the enumeration for pretty-printing indentation in XMLCoder. Use this to specify how XML output should be indented.
```swift
public enum PrettyPrintIndentation
```
--------------------------------
### Define NonConformingFloatDecodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NonConformingFloatDecodingStrategy
The enumeration definition for handling non-conforming floating-point values.
```swift
public enum NonConformingFloatDecodingStrategy
```
--------------------------------
### DateEncodingStrategy: millisecondsSince1970
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DateEncodingStrategy
Encode the Date as a UNIX millisecond timestamp, represented as an XML number.
```swift
case millisecondsSince1970
```
--------------------------------
### Define External Enumeration in XMLCoder
Source: https://coreoffice.github.io/XMLCoder/XMLDocumentType_External
Defines the External enumeration conforming to String, used for specifying external document types.
```swift
public enum External: String
```
--------------------------------
### Define nodeDecoding Requirement
Source: https://coreoffice.github.io/XMLCoder/DynamicNodeDecoding
The static function signature required by the DynamicNodeDecoding protocol.
```swift
static func nodeDecoding(for key: CodingKey) -> XMLDecoder.NodeDecoding
```
--------------------------------
### XMLDecoder.DataDecodingStrategy Enumeration
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_DataDecodingStrategy
Defines the strategies for decoding Data values within the XMLDecoder framework.
```APIDOC
## Enumeration XMLDecoder.DataDecodingStrategy
### Description
The strategy to use for decoding Data values when using XMLDecoder.
### Enumeration Cases
- **deferredToData**: Defer to Data for decoding.
- **base64**: Decode the Data from a Base64-encoded string. This is the default strategy.
- **custom**: Decode the Data as a custom box decoded by the given closure: `((_ decoder: Decoder) throws -> Data)`
```
--------------------------------
### Define NodeEncoding Enumeration
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NodeEncoding
Defines the possible encoding types for an XML node. Use this to specify how a node should be represented in XML.
```swift
public enum NodeEncoding
```
--------------------------------
### Decode Node as Attribute
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NodeDecoding
Specifies that a node should be decoded from XML attributes. Use this when your XML structure uses attributes to store node values.
```swift
case attribute
```
--------------------------------
### Attribute Property Wrapper
Source: https://coreoffice.github.io/XMLCoder/Attribute
The Attribute property wrapper allows you to specify that a property should be encoded and decoded as an XML attribute.
```APIDOC
## Structure `Attribute`
```swift
@propertyWrapper
public struct Attribute: XMLAttributeProtocol
```
Property wrapper specifying that a given property should be encoded and decoded as an XML attribute.
### Example Usage
```swift
struct Book: Codable {
@Attribute var id: Int
}
// Encoding: Book(id: 42) will encode as
// Decoding: will decode into Book(id: 42)
```
### Conforms To
- `Codable`
- `ExpressibleByBooleanLiteral`
- `ExpressibleByExtendedGraphemeClusterLiteral`
- `ExpressibleByIntegerLiteral`
- `ExpressibleByNilLiteral`
- `ExpressibleByStringLiteral`
- `ExpressibleByUnicodeScalarLiteral`
### Initializers
#### `init(_:)`
```swift
public init(_ wrappedValue: Value)
```
### Properties
#### `wrappedValue`
```swift
public var wrappedValue: Value
```
```
--------------------------------
### StringEncodingStrategy Enumeration
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_StringEncodingStrategy
Defines the strategies available for encoding String values when using XMLEncoder.
```APIDOC
## Enumeration StringEncodingStrategy
### Description
The strategy to use for encoding String values within the XMLEncoder.
### Member Of
XMLEncoder
### Enumeration Cases
- **deferredToString**: Defer to String for choosing an encoding. This is the default strategy.
- **cdata**: Encode the String as a CData-encoded string.
```
--------------------------------
### Define nodeEncoding for Array
Source: https://coreoffice.github.io/XMLCoder/Array
Specifies the node encoding strategy for a given coding key.
```swift
public static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding
```
--------------------------------
### Enumeration XMLEncoder.DateEncodingStrategy
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DateEncodingStrategy
The DateEncodingStrategy enumeration defines how Date values are encoded into XML. It offers several predefined strategies and a custom option.
```APIDOC
## Enumeration `XMLEncoder.DateEncodingStrategy`
### Description
The strategy to use for encoding `Date` values.
### Member Of
- `XMLEncoder`
### Enumeration Cases
#### `deferredToDate`
- **Description**: Defer to `Date` for choosing an encoding. This is the default strategy.
#### `secondsSince1970`
- **Description**: Encode the `Date` as a UNIX timestamp (as a XML number).
#### `millisecondsSince1970`
- **Description**: Encode the `Date` as UNIX millisecond timestamp (as a XML number).
#### `iso8601`
- **Description**: Encode the `Date` as an ISO-8601-formatted string (in RFC 3339 format).
- **Availability**: macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0
#### `formatted`
- **Description**: Encode the `Date` as a string formatted by the given formatter.
- **Parameters**:
- `DateFormatter` (DateFormatter) - Required - The formatter to use for encoding the date.
#### `custom`
- **Description**: Encode the `Date` as a custom value encoded by the given closure. If the closure fails to encode a value into the given encoder, the encoder will encode an empty automatic container in its place.
- **Parameters**:
- `(Date, Encoder) throws -> ()` (Closure) - Required - The closure that performs the custom encoding.
```
--------------------------------
### Declare XMLEncoder Class
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Declares the XMLEncoder class, which facilitates the encoding of Encodable values into XML.
```swift
open class XMLEncoder
```
--------------------------------
### Enumeration PrettyPrintIndentation
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_PrettyPrintIndentation
The PrettyPrintIndentation enumeration defines the indentation styles for pretty-printing XML.
```APIDOC
## Enumeration `PrettyPrintIndentation`
### Description
The indentation to use when XML is pretty-printed.
### Member Of
`XMLEncoder`
### Enumeration Cases
#### `spaces`
```swift
case spaces(Int)
```
#### `tabs`
```swift
case tabs(Int)
```
```
--------------------------------
### Define DateEncodingStrategy Enum
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_DateEncodingStrategy
The strategy to use for encoding Date values. This is the main enumeration for controlling date encoding behavior.
```swift
public enum DateEncodingStrategy
```
--------------------------------
### Encode Value
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Encodes a top-level Encodable value into its XML representation. This is a simpler version that infers the root key.
```swift
open func encode(_ value: T) throws -> Data where T: Encodable
```
--------------------------------
### Configure Characters Escaped in Elements
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Configures the characters and their escaped representations to be escaped within XML elements. This property allows customization of character escaping rules for elements.
```swift
open var charactersEscapedInElements = [
("&", "&"),
("<", "<"),
(">", ">"),
("'", "'"),
("\"", """),
]
```
--------------------------------
### Configure Characters Escaped in Attributes
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Configures the characters and their escaped representations to be escaped within XML attributes. This property allows customization of character escaping rules for attributes.
```swift
open var charactersEscapedInAttributes = [
("&", "&"),
("<", "<"),
(">", ">"),
("'", "'"),
("\"", """),
]
```
--------------------------------
### Define XMLNodeEncoderClosure Type Alias
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder
Defines a closure type for encoding nodes, taking a CodingKey and returning an optional NodeEncoding.
```swift
public typealias XMLNodeEncoderClosure = (CodingKey) -> NodeEncoding?
```
--------------------------------
### XMLDecodableSequence Protocol
Source: https://coreoffice.github.io/XMLCoder/XMLDecodableSequence
The XMLDecodableSequence protocol is a type-erased protocol helper used for metatype checks within generic `decode` overloads. If your custom sequence type is not decoding correctly, consider conforming it to this protocol. XMLCoder provides default conformances for `Array` and `Dictionary`.
```APIDOC
## Protocol `XMLDecodableSequence`
```swift
public protocol XMLDecodableSequence
```
### Description
Type-erased protocol helper for a metatype check in generic `decode` overload. If you custom sequence type is not decoded correctly, try making it confirm to `XMLDecodableSequence`. Default conformances for `Array` and `Dictionary` are already provided by the XMLCoder library.
### Requirements
#### `init()`
```swift
init()
```
```
--------------------------------
### XMLDecoder.NodeDecodingStrategy Enumeration
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NodeDecodingStrategy
The NodeDecodingStrategy enumeration provides different strategies for encoding XML nodes. It is a member of the XMLDecoder class, which facilitates decoding XML into Decodable types.
```APIDOC
## Enumeration `XMLDecoder.NodeDecodingStrategy`
### Description
Set of strategies to use for encoding of nodes.
### Member Of
`XMLDecoder`
`XMLDecoder` facilitates the decoding of XML into semantic `Decodable` types.
### Enumeration Cases
#### `deferredToDecoder`
##### Description
Defer to `Encoder` for choosing an encoding. This is the default strategy.
##### Code
```swift
case deferredToDecoder
```
#### `custom`
##### Description
Return a closure computing the desired node encoding for the value by its coding key.
##### Code
```swift
case custom((Decodable.Type, Decoder) -> ((CodingKey) -> NodeDecoding))
```
```
--------------------------------
### NonConformingFloatEncodingStrategy Enumeration
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_NonConformingFloatEncodingStrategy
Defines the strategies available for encoding non-conforming floating-point values within XMLEncoder.
```APIDOC
## Enumeration: NonConformingFloatEncodingStrategy
### Description
The strategy to use for non-XML-conforming floating-point values (IEEE 754 infinity and NaN) when using XMLEncoder.
### Member Of
- XMLEncoder
### Enumeration Cases
- **throw** - Throw upon encountering non-conforming values. This is the default strategy.
- **convertToString(positiveInfinity: String, negativeInfinity: String, nan: String)** - Encode the values using the given representation strings.
```
--------------------------------
### ElementAndAttribute Property Wrapper
Source: https://coreoffice.github.io/XMLCoder/ElementAndAttribute
The ElementAndAttribute property wrapper allows a property to be decoded from either an XML element or an XML attribute. When encoding, the value is present as both.
```APIDOC
## Structure `ElementAndAttribute`
### Description
Property wrapper specifying that a given property should be decoded from either an XML element or an XML attribute. When encoding, the value will be present as both an attribute, and an element.
### Example Usage
```swift
struct Book: Codable {
@ElementAndAttribute var id: Int
}
```
This will encode `Book(id: 42)` as `42`. It will decode both `42` and `` as `Book(id: 42)`.
### Conforms To
`Codable`
### Initializers
#### `init(_:)`
```swift
public init(_ wrappedValue: Value)
```
### Properties
#### `wrappedValue`
```swift
public var wrappedValue: Value
```
```
--------------------------------
### Define NodeDecoding Enumeration
Source: https://coreoffice.github.io/XMLCoder/XMLDecoder_NodeDecoding
Defines the enumeration for specifying how XML nodes are decoded. This is a fundamental part of XMLDecoder's configuration.
```swift
public enum NodeDecoding
```
--------------------------------
### XMLEncoder Class
Source: https://coreoffice.github.io/XMLCoder/XMLEncoder_PrettyPrintIndentation
XMLEncoder facilitates the encoding of Encodable values into XML.
```APIDOC
## Class `XMLEncoder`
### Description
XMLEncoder facilitates the encoding of `Encodable` values into XML.
```