Sample code for 30+ languages & platforms
Zig

Creating a New Child Node

See more XML Examples

Demonstrates how to create a new child in an XML document.

The following XML sample code produces this output:


<abc>
    <xyz>
        <mmm>123</mmm>
    </xyz>
</abc>

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");

    // Create a new child  with no content
    // and return the newly created child node:
    const child_node = try xml.newChild("xyz", "");
    defer child_node.deinit();

    // Create a child under childNode, but instead call
    // NewChild2 which doesn't return the newly created child node:
    child_node.newChild2("mmm", "123");

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