Sample code for 30+ languages & platforms
Zig

Load MIME from XML

See more MIME Examples

Demonstrates the Chilkat Mime.LoadXml method, which reconstructs a MIME tree from Chilkat's MIME XML. The only argument is the XML string.

Background: Chilkat can represent a MIME tree as XML — headers as elements, parameters as attributes — which is convenient for inspecting or editing structure with XML tools. This is the inverse of GetXml: it rebuilds the full MIME object from that representation. Invalid XML leaves the current object unchanged.

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

    // Demonstrates the Mime.LoadXml method, which reconstructs a MIME tree from Chilkat's MIME XML.
    // The only argument is the XML string.

    const mime = try chilkat.Mime.init();
    defer mime.deinit();

    // Chilkat MIME XML (as produced by GetXml).
    const xml_text = "<mime><contentType>text/plain</contentType><body>Hello.</body></mime>";

    mime.loadXml(xml_text) catch {
        std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Content-Type: {s}\n", .{try mime.getContentType(alloc)});
}