XML to serde.zig

XML documents convert to Zig structs annotated for serde.zig, including xml_root for the document element and xml_attribute for fields that came from attributes.

Target

API responseSmallest int widths from observed range; auto enum suggestion; missing/null become optional.

<user id="42">
  <name>Alice</name>
  <role>admin</role>
</user>
XML 5 lines 65 B Drop files here to add samples
User.zig
const serde = @import("serde");

pub const User = struct {
    name: []const u8,
    role: []const u8,
    id: u8,

    pub const serde = .{
        .xml_root = "user",
        .xml_attribute = .{ .id },
    };
};
loading zig fmt 1 struct · 3 fields 12 lines

Field decisions

Why each field got its type. Click a row to see it in the input; edit to override.

struct User $ 3 fields

serde.zig XML options zigshape emits

  • .xml_root = "user" on the root struct.
  • .xml_attribute = .{ .id } for attribute fields.
  • .rename for prefixed or non-snake_case element names.

Questions

Does serde.zig read mixed content?
No. serde.zig 1.2.3 skips text in an element that also has attributes or children, so zigshape makes that field optional and adds a note.