Sample code for 30+ languages & platforms
Zig

Xml.UpdateAttrAt Example #2

Another Xml.UpdateAttrAt example...

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const xml = try chilkat.Xml.init();
    defer xml.deinit();
    xml.setTag("abc");

    const sb_value = try chilkat.StringBuilder.init();
    defer sb_value.deinit();

    var i: i32 = 0;
    while (i < 10) {
        xml.setI(i);
        sb_value.clear();
        sb_value.appendInt(i) catch {};
        xml.updateAttrAt("xyz|test[i]", true, "index", try sb_value.getAsString(alloc)) catch {};
        i = i + 1;
    }

    std.debug.print("{s}\n", .{try xml.getXml(alloc)});

    // Output is:

    //     <?xml version="1.0" encoding="utf-8" ?>
    //     <abc>
    //         <xyz>
    //             <test index="0" />
    //             <test index="1" />
    //             <test index="2" />
    //             <test index="3" />
    //             <test index="4" />
    //             <test index="5" />
    //             <test index="6" />
    //             <test index="7" />
    //             <test index="8" />
    //             <test index="9" />
    //         </xyz>
    //     </abc>
}