xsql

CLI

Invocation modes, options, and the REPL.

Options

xsql - SQL-like language for querying and mutating XML files

Usage:
  xsql                          interactive mode (REPL)
  xsql <script.xsql>            run a script file
  xsql -e "<query>"             run an inline query
  <producer> | xsql             read the script from stdin
  <xml> | xsql script.xsql      pipe an XML document to `USE INPUT`

Options:
  -e, --eval <QUERY>   inline query
  -h, --help           show this help
  -V, --version        show version

A script file and -e are mutually exclusive. -e and a script file argument can't both be given.

Output

Output always goes to stdout:

  • SELECT results print immediately, in script order.
  • Every document a script actually modified is serialized (pretty-printed) once the whole script finishes.

Errors go to stderr with file:line:col diagnostics, and the process exits non-zero.

USE INPUT: filter mode

USE INPUT selects the XML document piped in on stdin, instead of a file on disk — this is what makes xsql a proper Unix filter:

cat db.xml | xsql -e "USE INPUT UPDATE goods SET cost = cost * 2;" > db.xml

If a script uses USE INPUT but the script itself didn't come from stdin (e.g. it was a file or -e query), xsql reads the XML document from stdin separately.

REPL

Running xsql with no arguments and nothing piped in starts an interactive session, like node or python:

xsql 0.1.0 — interactive mode
End statements with `;`. Commands: .help  .dump (print modified docs)  exit

xsql> USE db.xml
 ...> SELECT GROUP goods;
  • A statement runs once it lexes cleanly and its last token is the ; terminator — unterminated strings or RAW XML blocks keep the continuation prompt (...>) open for multi-line input.
  • USE and any in-memory edits persist across statements in the same session.
  • .dump prints every document modified so far.
  • .help shows the usage banner.
  • exit / quit / .exit (or EOF, Ctrl+D / Ctrl+Z) leaves the REPL — emitting any pending edits to stdout on the way out, so xsql > out.xml still captures them.

Diagnostics

SET ANALYZE = ON (or the ANALYZE; shorthand) prints a per-stage timing report to stderr after the run: lex, parse, stdin/file read, XML parse per document, per-block execution, serialization, output assembly, stdout write, total DOM memory, and total time. See Settings.

On this page