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.
API responseSmallest int widths from observed range; auto enum suggestion; missing/null become optional.
<user id="42"> <name>Alice</name> <role>admin</role> </user>
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 },
};
};
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..renamefor 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.