When an element stores its text content via the empty-string CodingKey (""), XMLEncoder pretty printing splits the intrinsic value onto its own line instead of keeping the element inline.
Minimal example:
struct Measurement: Codable {
@Attribute var ref: String?
var value: Double
enum CodingKeys: String, CodingKey {
case ref
case value = ""
}
}
let encoder = XMLEncoder()
encoder.outputFormatting = [.prettyPrinted]
encoder.prettyPrintIndentation = .spaces(4)
Actual output:
<measurement ref="sensor-1">
120000.0
</measurement>
Expected output:
<measurement ref="sensor-1">120000.0</measurement>
This also affects the same intrinsic-value shape when the element has no attributes.
When an element stores its text content via the empty-string CodingKey (
""),XMLEncoderpretty printing splits the intrinsic value onto its own line instead of keeping the element inline.Minimal example:
Actual output:
Expected output:
This also affects the same intrinsic-value shape when the element has no attributes.