Zig
Zig
Load XML from a Remote URL
Demonstrates how to load XML from a remote URL, such as https://www.chilkatsoft.com/hamlet.xmlChilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
const sb_xml = try chilkat.StringBuilder.init();
defer sb_xml.deinit();
// Download the XML from the URL into sbXml
http.quickGetSb("https://www.chilkatsoft.com/hamlet.xml", sb_xml) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const xml = try chilkat.Xml.init();
defer xml.deinit();
// Load the XML contained in sbXml
xml.loadSb(sb_xml, true) catch {
std.debug.print("{s}\n", .{try xml.getLastErrorText(alloc)});
return;
};
std.debug.print("Success.\n", .{});
}