Skip to content
sxml 0.2.0 · MIT License

An XML toolchain in portable C.

sxml parses XML and HTML, validates documents against XSD 1.1 schemas and DTDs, and runs XPath 4.0, XQuery 4.0 and XSLT 4.0. It is a C library with no dependencies, the sxml command, and a WebAssembly module for JavaScript.

One order through every language

Three lines of text become XML, are validated, queried, rebuilt and rendered as HTML. The files and outputs below are real, recorded with the sxml command.

order.txtorder.xmlreceipt.xmlreceipt.html

An Invisible XML grammar describes the order's text format. fn:invisible-xml compiles the grammar into a function, and the function turns the text into XML.

order.txt
2 x tea @ 3.50
1 x coffee @ 4.20
3 x scone @ 2.10
order.ixml
order: line+.
line: quantity, -" x ", item, -" @ ", price, -#a.
quantity: digit+.
item: ["a"-"z"]+.
price: digit+, ".", digit, digit.
-digit: ["0"-"9"].
sxml xpath --method=xml \
  'invisible-xml(unparsed-text("order.ixml"))(unparsed-text("order.txt"))' \
  -o order.xml
sxml serialize --indent order.xml
<order>
  <line>
    <quantity>2</quantity>
    <item>tea</item>
    <price>3.50</price>
  </line>
  <line>
    <quantity>1</quantity>
    <item>coffee</item>
    <price>4.20</price>
  </line>
  <line>
    <quantity>3</quantity>
    <item>scone</item>
    <price>2.10</price>
  </line>
</order>

Standards

All languages share one data model, XDM 4.0, and every build includes every feature.

Parsing
XML 1.0 (Fifth Edition) and XML 1.1, Namespaces in XML 1.0 and 1.1, from UTF-8, UTF-16, ISO-8859-1 and US-ASCII
DTDs
Internal and external subsets, external entities, attribute defaults, DTD validation
HTML
Parsing as the HTML Living Standard specifies it, in every encoding of the Encoding Standard
Expressions
XPath 4.0 and the F&O 4.0 function library: maps, arrays, records, higher-order functions, regular expressions, dates and times, JSON and CSV
Queries
XQuery 4.0, the XQuery Update Facility 3.0, XQuery and XPath Full Text 3.0
Transformations
XSLT 4.0 with streaming, packages, accumulators and xsl:evaluate; XSLT 1.0, 2.0 and 3.0 stylesheets; EXSLT Common
Schemas
XSD 1.1 validation; schema-aware XPath, XQuery and XSLT
Output
Serialization 4.0: xml, xhtml, html, text, json, csv and adaptive
Grammars
Invisible XML 1.0
Extensions
EXPath Binary 4.0 and EXPath File 4.0
Text
Unicode 16.0, the Unicode Collation Algorithm with CLDR tailorings, the IANA Time Zone Database

Design

Portable C17

One code base. It depends on nothing outside the repository and builds with Clang, GCC and Zig.

Caller-provided memory

The library never calls malloc. Every object takes an sxml_allocator, or goes in memory you provide after a memory_requirements query.

No recursion

The parsers and the evaluator use explicit stacks. Deeply nested input does not overflow the C stack; depth and work have limits you configure.

One evaluator

XPath, XQuery and XSLT compile to one intermediate representation, run on one evaluator and share one data model, XDM 4.0.

No global state

Separate processors share nothing, so a program can run as many as it needs, on as many threads.

No network access

sxml reads only what your resource resolver gives it. File access through EXPath File is off until a host turns it on.

Streaming

In an XSLT mode declared streamable="yes", sxml transform reads its input as it parses it and does not build a tree. Summing one million orders in a 76 MB document takes 11 MB of memory; a 974 MB document also takes 11 MB.

streamed11 MB
tree597 MB
Peak memory of sxml transform total.xsl orders.xml on a 76 MB input

Conformance

Results against the W3C and community test suites, from a release build at commit e74d4ad on 2026-10-20.

SuiteRunPassedRate
XPath 4.0 and F&O 4.0QT4 · XP4032,84132,815
99.92 %
XQuery 4.0, Update and Full TextQT4 · XQ4046,23246,158
99.84 %
XSLT 4.0XT4012,51812,268
98.00 %
XSD 1.1W3C XSD test suite41,61041,599
99.97 %
XML 1.0 and 1.1W3C XML Conformance Test Suite2,2372,237
100.00 %
HTML tokenizerhtml5lib7,0457,045
100.00 %
Invisible XMLCommunity test suite886886
100.00 %

Bars start at 95 %. Results by test set

Platforms

Linux · macOS · Windows · WASI

The sxml command

Subcommands check, validate, xpath, xquery, transform and serialize. Static executables for x86_64 and AArch64, and a WebAssembly program for WASI runtimes.

sxml help
C17 · static or shared

The C library

A processor holds names, types and values. Expressions, queries, stylesheets and schemas compile once and run against any number of documents.

#include "sxml/xpath.h"
Browsers · Node.js

JavaScript

The @tinyactors/sxml package: the same library compiled to WebAssembly, with a TypeScript API and no runtime dependencies.

import { load } from '@tinyactors/sxml'

The sxml Book

A guide to sxml and its languages: installing it, XPath, XQuery, XSLT, XSD, other formats, and embedding sxml in C and JavaScript. Each part is taught on a project for one made-up feature-flag service, from its specification to its generated SDK clients.

Released under the MIT License.