xq1
Command-line xml and html beautifier and content extractor
Usage
xq [options ...]
[file]
Overview
Formats the provided file and outputs it in the colorful mode. The file can be provided as an argument or via stdin.
Options
-
--version | -v -
Prints versions information and exits.
-
--help | -h -
Prints the synopsis and a list of options and exits.
-
--indent int -
Uses the given number of spaces for indentation (default 2).
-
--color | -c -
Forces colorful output.
-
--no-color -
Disables colorful output (only formatting).
-
--tab -
Uses tabs instead of spaces for indentation.
-
--xpath | -x string -
Extracts the node(s) from XML using provided XPath query.
-
--extract | -e string -
Extracts a single node from XML using provided XPath query.
-
--query | -q string -
Extracts the node(s) using CSS selector.
-
--attr | -a string -
Extracts an attribute value instead of node content for provided CSS query.
-
--html | -m -
Uses HTML formatter instead of XML.
-
--node | -n -
Returns the node content instead of text.
Examples
Format an XML file and highlight the syntax:
$ xq test/data/xml/unformatted.xml
Utility also accepts input through stdin:
$ curl -s https://www.w3schools.com/xml/note.xml | xq
HTML content can be formatted and highlighted using -m flag:
$ xq -m test/data/html/formatted.html
Extract the text content of all nodes with city name:
$ cat test/data/xml/unformatted.xml | xq -x //city
Extract the XML content of all nodes with city name:
$ cat test/data/xml/unformatted.xml | xq -n -x //city
Releases
2 releases since Debian 12 (Bookworm); the text changed 1 time.
--attr since Debian 13 (Trixie);
--color since Debian 13 (Trixie);
--node since Debian 13 (Trixie);
--query since Debian 13 (Trixie);
-a since Debian 13 (Trixie);
-c since Debian 13 (Trixie);
-n since Debian 13 (Trixie);
-q since Debian 13 (Trixie).