oxml-cli 0.0.17

Command-line XML querying, validation and formatting, powered by oxml
Documentation

Contents

Getting started

The oxml-cli ecosystem

Library reference

Operational


Install

As a Rust library

[dependencies]
oxml-cli = "0.0.17"

The library exposes oxml_cli::run, which the binary, the tests and the benchmarks all drive. Most users want the binary:

cargo install oxml-cli --version 0.0.17 --locked

From source:

git clone https://github.com/sebastienrousseau/oxml-cli
cd oxml-cli
cargo install --path .

The binary is called oxml.


Requirements

  • Rust 1.89.0 or later. CI builds on exactly that version on every push; see doc/POLICIES.md.
  • No C dependencies and no build toolchain beyond Cargo. If cargo works, this installs.
  • Platforms: CI builds and tests on Linux, macOS and Windows.

Quick Start

$ oxml query -t '//title' catalogue.xml
Dune
Germinal

$ oxml check catalogue.xml
well-formed (21 nodes)

$ oxml stats catalogue.xml
nodes       21
elements    7
attributes  4
text        8
comments    1
max depth   4

query evaluates XPath 1.0, check reports well-formedness with a line and column, and stats summarises what is in a file before you write a query against it.


The oxml-cli ecosystem

All seven crates ship one version number, moving in steps of 0.0.1. oxml-cli pins its oxml and xmlschema dependencies to exact versions with =, and no other combination is supported.

Component Purpose Use case
oxml Parser, tree, XPath 1.0 Reading XML from Rust
xmlschema XSD validation Checking a document against a schema
oxml-cli The command line Querying and checking XML in a shell or CI
oxml-wasm WebAssembly bindings XML in a browser or JavaScript runtime
oxml-mcp Model Context Protocol server Giving an agent XML tools
oxml-lsp XML analysis and linting Editor diagnostics
oxml-json JSON support for the language server Protocol messages for oxml-lsp

Capabilities at a glance

Area Capability Status
Query XPath 1.0: ten axes, 25 functions, all four value types Available
Query Text-only (-t) and count-only (-c) output Available
Query Namespace prefixes bound on the command line (-n, --ns) Available
Validation XSD validation via xmlschema Available
Inspection Well-formedness with line and column Available
Inspection Node counts by kind, and maximum depth Available
Input Standard input; UTF-8, UTF-16 and ISO-8859-1 Available
Scripting Exit codes that separate "no match" from "usage error" Available
Output Formatting or pretty-printing Not yet
Output Editing, XInclude, XSLT Not yet

Ecosystem comparison

oxml is measured against xmllint, the tool it is most often used in place of, and against xmlstarlet, which shows how much a command-line XML tool can do.

Project XSD validation Single static binary Fetches external entities
oxml-cli Yes Yes Never
xmllint Yes No (libxml2) Configurable
xmlstarlet Yes No (libxml2) Configurable

See doc/COMPARISON.md for the evidence and complete matrix.


Benchmarks

cargo bench --bench commands

Timings are per invocation with process spawn excluded, because spawn is the operating system's business and swamps everything else on a small document. No absolute throughput figure is published: the same benchmark binary measured 14.7 and 123.1 MB/s on one machine on one day, at a load average above 30. The benchmark reports paired comparisons instead.

Scenario Result Environment
Argument handling and file I/O over the bare parse about 9% 200 KB document, spawn excluded
--help under 1 µs spawn excluded

See oxml's BENCHMARKS.md for methodology and full results.


Features

query <XPATH> [FILE]

Evaluate an XPath 1.0 expression.

$ oxml query '//title' catalogue.xml
<title>Dune</title>
<title>Germinal</title>

By default each match is printed as a summary of the node. -t prints the text instead, and -c prints only how many matched. Non-node results (numbers, strings, booleans) are printed directly:

$ oxml query 'count(//book)' catalogue.xml
2
$ oxml query 'sum(//price)' catalogue.xml
17.49

validate <XSD> [FILE]

Validate against an XML Schema.

$ oxml validate schema.xsd catalogue.xml
valid

Exit status 0 means the document conforms, 1 means it does not. The schema comes first because the document is the argument that defaults to standard input.

stats [FILE]

Summarise the document: node counts by kind, and maximum depth. Useful for finding out what is in a file before writing a query against it, and for spotting a document that is deeper or larger than expected.

check [FILE]

Report whether the document is well-formed.

$ oxml check broken.xml
not well-formed at 1:12: at byte 11: input ended unexpectedly

The position is a line and column, counted in characters, so it points where an editor would.

Options

Option Effect
-t, --text Print matched nodes' text rather than a summary
-c, --count Print only the number of matches
-n, --ns P=URI Bind a namespace prefix for query; repeatable
-h, --help Usage
-V, --version Version

-t and -c apply to query. Both accept the flag anywhere in the argument list. An unbound prefix is an error, not a silent match on the local part; see doc/NAMESPACES.md.

Exit status

Code Meaning
0 Success; for validate, the document conforms
1 The document is invalid, or no nodes matched
2 A usage or I/O error

The distinction between 1 and 2 is the point. A shell script that tests if oxml query ... ; then wants to know "did anything match", and it must not confuse that with "you passed a path that does not exist". A tool that returns 1 for both makes set -e a liability.

if oxml query -c '//error' build.xml > /dev/null; then
  echo "the build reported errors"
fi

Reading from standard input

FILE defaults to standard input, so oxml composes:

curl -s https://example.com/feed.xml | oxml query -t '//item/title'
unzip -p document.docx word/document.xml | oxml query -c '//w:p'
find . -name '*.xml' -exec oxml check {} \;

Configuration

There is none. No config file, no environment variables, no dotfile.

That is a decision rather than an omission: a command whose behaviour depends on a file somewhere in your home directory behaves differently in CI than on your laptop, and the difference surfaces as a confusing failure. Everything oxml does is on the command line.

File and stdin reads stop at 8 MiB. Parsing and XPath compilation use Limits::strict(); each query uses EvalLimits::default() to bound work, intermediate nodes and strings. Exceeding a budget is an error, not a partial result.


Examples

Runnable scripts live in examples/, each with the sample document it operates on. They run in CI, so they cannot rot.

Example What it shows
query-basics.sh Every output mode of query
pipeline.sh Standard input, exit codes, composing with other tools
inspect.sh stats and check, including a malformed document
validate.sh XSD validation, valid and invalid

Coming from another tool: doc/MIGRATION-FROM-XMLLINT.md maps xmllint and xmlstarlet commands to oxml, and doc/USER-GUIDE.md collects recipes.


When not to use oxml-cli

  • You need to edit XML. xmlstarlet ed does; this does not.
  • You need to format or pretty-print. xmllint --format does.
  • You need XSLT. xsltproc.
  • You need XPath 2.0 or 3.1. This is 1.0, so no matches(), no for, no sequences.
  • The document is larger than memory. The whole tree is built, and reads stop at 8 MiB.

Development

make gate         # everything CI runs, in the order that fails fastest
make complexity   # per-function complexity against complexity-baseline.tsv
make test         # cargo test --all-features
make clippy       # clippy with -D warnings
cargo bench --bench commands

make gate runs scripts/gate.sh: the workflow contract tests, format, clippy, tests, rustdoc, the complexity ratchet, the #![forbid(unsafe_code)] check, the examples, the 95% coverage floor, the published-figures and package checks, and an MSRV build. It pins the toolchain rather than trusting rust-toolchain.toml, because a RUSTUP_TOOLCHAIN in the environment silently overrides that file.

Fuzz targets live in fuzz/ and run in CI. CI also runs the test suite on Linux, macOS and Windows.


Security

The parser underneath never dereferences external entities, so XXE is foreclosed structurally rather than by a default: a document containing <!ENTITY xxe SYSTEM "file:///etc/passwd"> cannot make oxml read that file. Entity expansion is bounded. There is no network code in the dependency tree. The crate is #![forbid(unsafe_code)].

Scorecard scans use a digest-pinned upstream image. Results are retained as CI artifacts and repository posture findings in GitHub code scanning, not published to Scorecard's public service. The badge shows workflow status, not a security score; a successful scan can still report findings. The project holds an OpenSSF Best Practices badge. The threat model is in doc/SECURITY-MODEL.md and the argument for it in doc/ASSURANCE-CASE.md.

Report vulnerabilities according to SECURITY.md.


Documentation


Stability guarantees

  • Versioning. The family moves in steps of 0.0.1 and every member ships the same version. Before 0.1.0, any release may change the command line; changes are listed in CHANGELOG.md.
  • Output. query -t and query -c are stable enough to parse: one result per line, nothing else on stdout. stats and the default query output are human-facing and may change.
  • Exit codes. 0, 1 and 2 keep the meanings in Exit status.
  • Minimum toolchain. Rust 1.89.0, enforced in CI on every push. The floor moves with the family and is recorded in the CHANGELOG; see doc/POLICIES.md.

License

Licensed under either of

at your option.

oxml-cli is measured against xmllint, the reason the exit-code behaviour is what it is; owes the idea of how much a command-line XML tool can do to xmlstarlet; and holds itself to the standard jq set for pipeline-friendly query tools.