Skip to content

Pretty-printed intrinsic-value elements are split across multiple lines #295

@weppos

Description

@weppos

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions