Something went wrong. Try again.
An XML document tree and serializer for Zig 0.16, built on zxml.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! An XML document tree for Zig 0.16: parents, document order, expanded names,//! and a serializer to write one back out.//!//! [zxml][] is a pull parser, which is the right shape for reading a document//! once and the wrong shape for anything that needs to ask questions about it.//! `chapter/title` wants a parent. Sorting a set of nodes and then restoring//! document order wants an order to restore. Indexing every element by an//! attribute wants random access. None of that is answerable from a stream, so//! this reads the stream once and builds the tree those questions need.//!//! [zxml]: https://git.jcollie.dev/jeff/zxml//!//! The tree is also a *builder*, because the interesting thing to do with a//! document is usually to produce another one. Nodes are appended, attributes//! are set, and `serialize` turns the result into bytes by one of three output//! methods. That is why `Document` has as many functions for writing as for//! reading.//!//! ```zig//! const ztree = @import("ztree");//!//! const doc = try ztree.parse(gpa, source, .{});//! defer doc.destroy();//!//! const root = doc.documentElement().?;//! for (doc.node(root).children.items) |child| {//! if (doc.node(child).kind != .element) continue;//! std.debug.print("{s}\n", .{doc.node(child).name.local});//! }//!//! const out = try ztree.serialize.toOwnedSlice(gpa, doc, .{ .indent = true });//! defer gpa.free(out);//! ```
const std = @import("std");
pub const tree = @import("tree.zig");pub const serialize = @import("serialize.zig");pub const validate = @import("validate.zig");
// The tree is what this library is, so its names are the library's names// rather than sitting a module down. `ztree.serialize` stays where it is// because writing a document out is a separate job from holding one.pub const Document = tree.Document;pub const Node = tree.Node;pub const NodeId = tree.NodeId;pub const NodeRef = tree.NodeRef;pub const Kind = tree.Kind;pub const Name = tree.Name;pub const NsDecl = tree.NsDecl;
pub const parse = tree.parse;pub const ParseError = tree.ParseError;pub const ParseOptions = tree.ParseOptions;pub const WhitespaceMode = tree.WhitespaceMode;
/// The namespace the `xml` prefix is bound to without being declared.pub const xml_ns = tree.xml_ns;/// The namespace `xmlns` itself is in.pub const xmlns_ns = tree.xmlns_ns;
test { std.testing.refAllDecls(@This());}