Sample code for 30+ languages & platforms
Zig

Decode HTML Entities found in XML

Demonstrates how to decode HTML entities found in XML.

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

    // Load an XML file containing the following:

    // <?xml version="1.0" encoding="UTF-8"?>
    // <output>Franz&#xf6;sische</output>

    const xml = try chilkat.Xml.init();
    defer xml.deinit();
    try xml.loadXmlFile("qa_data/xml/hasHtmlEntity.xml");

    // Get non-decoded content, then get decoded content.

    // Result is Franz&#xf6;sische
    std.debug.print("{s}\n", .{try xml.getContent(alloc)});

    // Result is Französische
    const str_decoded = try xml.decodeEntities(alloc, try xml.getContent(alloc));
    std.debug.print("{s}\n", .{str_decoded});
}