oxml-cli 0.0.17

Command-line XML querying, validation and formatting, powered by oxml
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<!-- SPDX-License-Identifier: Apache-2.0 OR MIT -->

<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://github.com/sebastienrousseau/oxml-cli/actions/workflows/scorecard.yml"><img src="https://img.shields.io/github/actions/workflow/status/sebastienrousseau/oxml-cli/scorecard.yml?style=for-the-badge&label=Scorecard%20scan&logo=openssf" alt="Scorecard scan workflow status" 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.17"
```

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.17 --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.

| Component | Purpose | Use case |
| :--- | :--- | :--- |
| [`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

| 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`](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.

| 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`](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

| 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`](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.

```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
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/`](examples/), each with the sample
document it operates on. They run in CI, so they cannot rot.

| Example | What it shows |
|---|---|
| [`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)]`.

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](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
- [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.