1
0
Fork
You've already forked xmlread
0
forked from kudu/xmlread
Little XML parser
  • Zig 100%
2026年06月01日 17:30:42 -05:00
src Upgrade to Zig 0.16.0 2026年04月21日 12:38:45 +02:00
tools Upgrade to Zig 0.16.0 2026年04月21日 12:38:45 +02:00
xmltest Initial commit 2025年09月16日 18:19:50 +02:00
.gitignore Initial commit 2025年09月16日 18:19:50 +02:00
build.zig Fix build.zig to work with both zig 0.16 and zig 0.17 2026年06月01日 17:30:42 -05:00
build.zig.zon Upgrade to Zig 0.16.0 2026年04月21日 12:38:45 +02:00
grammar.txt Initial commit 2025年09月16日 18:19:50 +02:00
LICENSE Initial commit 2025年09月16日 18:19:50 +02:00
README.md Upgrade to Zig 0.16.0 2026年04月21日 12:38:45 +02:00

xmlread

Little XML parser

  • XML version 1.0
  • encoding: UTF-8, UTF-16, ISO-8859-*
  • standalone XML

Installation

  • Add xmlread dependency to build.zig.zon

    # for zig-0.16.0
    zig fetch --save git+https://codeberg.org/kudu/xmlread#v0.2.0
    # for zig-0.15.1
    zig fetch --save git+https://codeberg.org/kudu/xmlread#v0.1.0
    
  • Add to build.zig:

    constxmlread=b.dependency("xmlread",.{.target=target,.optimize=optimize,});exe_mod.addImport("xml",xmlread.module("xml"));// Install `xmlread` executableb.installArtifact(xmlread.artifact("xmlread"));

Features

  • Pull parser iterating over XML items of a document
    (start-tag, end-tag, character data, comment, ...)
  • Load entire document tree into memory
  • Parsed strings are UTF-8 encoded.

Limitations

  • Document tree is read-only

Example

zig-0.16.0

conststd=@import("std");constxml=@import("xml");pubfnmain(init:std.process.Init)!void{constgpa=init.gpa;constio=init.io;vardoc=tryxml.tree.load(io,gpa,"test.xml",null);deferdoc.deinit(gpa);constroot=doc.root();std.debug.print("root element name: {s}\n",.{root.name()});std.debug.print("attribute a = {?s}\n",.{root.attr("a")});}

zig-0.15.1

conststd=@import("std");constxml=@import("xml");pubfnmain()!void{vargpa_state:std.heap.DebugAllocator(.{})=.init;defer_=gpa_state.deinit();constgpa=gpa_state.allocator();vardoc=tryxml.tree.load(gpa,"test.xml",null);deferdoc.deinit(gpa);constroot=doc.root();std.debug.print("root element name: {s}\n",.{root.name()});std.debug.print("attribute a = {?s}\n",.{root.attr("a")});}

see also

  • Tests in src/root.zig