<p align="center">
<img src="https://oxmllib.com/assets/logo.svg" alt="oxml-cli logo" width="128" />
</p>
<h1 align="center">oxml-cli</h1>
<p align="center">
Query, validate and inspect XML from a shell, with exit codes a script can branch on and zero <code>unsafe</code> code.
</p>
<p align="center">
<a href="https://github.com/sebastienrousseau/oxml-cli/actions"><img src="https://img.shields.io/github/actions/workflow/status/sebastienrousseau/oxml-cli/ci.yml?style=for-the-badge&logo=github" alt="Build" height="28" /></a>
<a href="https://crates.io/crates/oxml-cli"><img src="https://img.shields.io/crates/v/oxml-cli.svg?style=for-the-badge&color=fc8d62&logo=rust" alt="Registry" height="28" /></a>
<a href="https://docs.rs/oxml-cli"><img src="https://img.shields.io/badge/docs.rs-oxml--cli-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" alt="Docs" height="28" /></a>
<a href="https://scorecard.dev/viewer/?uri=github.com/sebastienrousseau/oxml-cli"><img src="https://img.shields.io/ossf-scorecard/github.com/sebastienrousseau/oxml-cli?style=for-the-badge&label=OpenSSF%20Scorecard&logo=openssf" alt="OpenSSF Scorecard" height="28" /></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg?style=for-the-badge" alt="License: Apache-2.0 OR MIT" height="28" /></a>
<a href="https://github.com/sebastienrousseau/oxml-cli/blob/main/doc/POLICIES.md"><img src="https://img.shields.io/badge/rust-1.89.0%2B-93450a.svg?style=for-the-badge&logo=rust" alt="Rust 1.89.0 or later" height="28" /></a>
</p>
<p align="center">
<img src="https://raw.githubusercontent.com/sebastienrousseau/oxml-cli/main/.github/demo.gif" alt="oxml printing its version and help, then querying a title and summarising a document read from standard input" width="100%" />
</p>
---
## Contents
**Getting started**
- [Install](#install): Cargo, or from source
- [Requirements](#requirements): toolchain floor, platforms
- [Quick Start](#quick-start): a query in one line
**The oxml-cli ecosystem**
- [The oxml-cli ecosystem](#the-oxml-cli-ecosystem): oxml, xmlschema, oxml-cli, oxml-wasm, oxml-mcp, oxml-lsp, oxml-json
**Library reference**
- [Capabilities at a glance](#capabilities-at-a-glance): the current surface by theme
- [Ecosystem comparison](#ecosystem-comparison): short matrix; full table at [`doc/COMPARISON.md`](doc/COMPARISON.md)
- [Benchmarks](#benchmarks): paired comparisons; methodology in oxml's [`BENCHMARKS.md`](https://github.com/sebastienrousseau/oxml/blob/main/doc/BENCHMARKS.md)
- [Features](#features): commands, options, exit status, standard input
- [Configuration](#configuration): there is none, and why
- [Examples](#examples): runnable example index
**Operational**
- [When not to use oxml-cli](#when-not-to-use-oxml-cli): limitations
- [Development](#development): make targets, fuzzing, CI
- [Security](#security): guarantees and compliance
- [Documentation](#documentation): all reference docs
- [Stability guarantees](#stability-guarantees): SemVer axis, output stability, minimum toolchain discipline
- [License](#license)
---
## Install
### As a Rust library
```toml
[dependencies]
oxml-cli = "0.0.19"
```
The library exposes `oxml_cli::run`, which the binary, the tests and
the benchmarks all drive. Most users want the binary:
```bash
cargo install oxml-cli --version 0.0.19 --locked
```
From source:
```bash
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`](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
```bash
$ 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.
| [`oxml`](https://github.com/sebastienrousseau/oxml) | Parser, tree, XPath 1.0 | Reading XML from Rust |
| [`xmlschema`](https://github.com/sebastienrousseau/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`](https://github.com/sebastienrousseau/oxml-wasm) | WebAssembly bindings | XML in a browser or JavaScript runtime |
| [`oxml-mcp`](https://github.com/sebastienrousseau/oxml-mcp) | Model Context Protocol server | Giving an agent XML tools |
| [`oxml-lsp`](https://github.com/sebastienrousseau/oxml-lsp) | XML analysis and linting | Editor diagnostics |
| [`oxml-json`](https://github.com/sebastienrousseau/oxml-json) | JSON support for the language server | Protocol messages for `oxml-lsp` |
---
## Capabilities at a glance
| 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.
| **oxml-cli** | Yes | Yes | **Never** |
| `xmllint` | Yes | No (libxml2) | Configurable |
| `xmlstarlet` | Yes | No (libxml2) | Configurable |
See [`doc/COMPARISON.md`](doc/COMPARISON.md) for the evidence and complete matrix.
---
## Benchmarks
```bash
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.
| 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`](https://github.com/sebastienrousseau/oxml/blob/main/doc/BENCHMARKS.md) for methodology and full results.
---
## Features
### `query <XPATH> [FILE]`
Evaluate an XPath 1.0 expression.
```bash
$ 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:
```bash
$ oxml query 'count(//book)' catalogue.xml
2
$ oxml query 'sum(//price)' catalogue.xml
17.49
```
### `validate <XSD> [FILE]`
Validate against an XML Schema.
```bash
$ 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.
```bash
$ 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
| `-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`](doc/NAMESPACES.md).
### Exit status
| 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.
```bash
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:
```bash
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/`](examples/), each with the sample
document it operates on. They run in CI, so they cannot rot.
| [`query-basics.sh`](examples/query-basics.sh) | Every output mode of `query` |
| [`pipeline.sh`](examples/pipeline.sh) | Standard input, exit codes, composing with other tools |
| [`inspect.sh`](examples/inspect.sh) | `stats` and `check`, including a malformed document |
| [`validate.sh`](examples/validate.sh) | XSD validation, valid and invalid |
Coming from another tool:
[`doc/MIGRATION-FROM-XMLLINT.md`](doc/MIGRATION-FROM-XMLLINT.md) maps
`xmllint` and `xmlstarlet` commands to `oxml`, and
[`doc/USER-GUIDE.md`](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
```bash
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/`](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)]`.
OpenSSF Scorecard runs on every push to `main` and weekly, and publishes
its score to the public service: the badge links to the full report.
The same results are kept as CI artifacts and as repository posture
findings in GitHub code scanning.
The project holds an
[OpenSSF Best Practices](https://www.bestpractices.dev/projects/14311)
badge. The threat model is in
[`doc/SECURITY-MODEL.md`](doc/SECURITY-MODEL.md) and the argument for
it in [`doc/ASSURANCE-CASE.md`](doc/ASSURANCE-CASE.md).
Report vulnerabilities according to [`SECURITY.md`](SECURITY.md).
---
## Documentation
- [`doc/`](doc/README.md): the decisions, in longer form
- [`doc/USER-GUIDE.md`](doc/USER-GUIDE.md): recipes
- [`doc/FAQ.md`](doc/FAQ.md): frequently asked questions
- [`doc/ARCHITECTURE.md`](doc/ARCHITECTURE.md): how the binary is put together
- [`doc/COMPARISON.md`](doc/COMPARISON.md): against `xmllint`, `xmlstarlet` and `xq`
- [docs.rs/oxml-cli](https://docs.rs/oxml-cli): the library API
- [User guide](https://oxmllib.com/cli/): the command-line chapter of
the oxml family manual at oxmllib.com
- [oxml's documentation](https://github.com/sebastienrousseau/oxml/tree/main/doc)
- [`CHANGELOG.md`](CHANGELOG.md) and [`CONTRIBUTING.md`](CONTRIBUTING.md)
---
## 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`](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](#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`](doc/POLICIES.md).
---
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))
at your option.
`oxml-cli` is measured against
[`xmllint`](https://gitlab.gnome.org/GNOME/libxml2), 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`](https://xmlstar.sourceforge.net/); and holds itself to
the standard [`jq`](https://jqlang.github.io/jq/) set for
pipeline-friendly query tools.