Back to rankings

sibprogrammer/xq

Go

Command-line XML and HTML beautifier and content extractor

terminalxmlsyntax-highlightingxpathhtmlformattercligolang
Star Growth
Stars
1.1k
Forks
35
Weekly Growth
Issues
12
5001k
Nov 2021May 2023Dec 2024Jul 2026
ArtifactsGo Modulesgo get github.com/sibprogrammer/xq
README

xq

build Codecov Scc Count Homebrew Macports

Command-line XML and HTML beautifier and content extractor.

xq

Features

  • Syntax highlighting
  • Automatic indentation and formatting
  • Automatic pagination
  • Node content extraction

Usage

Format an XML file and highlight the syntax:

xq test/data/xml/unformatted.xml

xq also accepts input through stdin:

curl -s https://www.w3schools.com/xml/note.xml | xq

HTML content can be formatted and highlighted as well (using -m flag):

xq -m test/data/html/formatted.html

Format multiple files at once:

xq test/data/xml/unformatted.xml test/data/xml/unformatted2.xml

In place formatting is supported as well (using -i flag):

xq -i test/data/xml/unformatted.xml

It is possible to extract the content using XPath query language. -x parameter accepts XPath expression.

Extract the text content of all nodes with city name:

cat test/data/xml/unformatted.xml | xq -x //city

Extract the value of attribute named status and belonging to user:

cat test/data/xml/unformatted.xml | xq -x /user/@status

See https://en.wikipedia.org/wiki/XPath for details.

It is possible to use CSS selector to extract the content as well:

cat test/data/html/unformatted.html | xq -q "body > p"

Extract an attribute value instead of node content additional option --attr (-a) can be used:

cat test/data/html/unformatted.html | xq -q "head > script" -a "src"

Extract part of HTML with tags (not only text content) using CSS selector:

cat test/data/html/unformatted.html | xq -n -q "head"

Output the result as JSON:

cat test/data/xml/unformatted.xml | xq -j

This will output the result in JSON format, preserving the XML structure. The JSON output will be an object where:

  • XML elements become object keys
  • Attributes are prefixed with "@"
  • Text content is stored under "#text" if the element has attributes or child elements
  • Repeated elements are automatically converted to arrays
  • Elements with only text content are represented as strings

Installation

The preferable ways to install the utility are described below.

For macOS, via Homebrew:

brew install xq

For macOS, via MacPorts:

sudo port install xq

For Linux using custom installer:

curl -sSL https://bit.ly/install-xq | sudo bash

For Linux using custom installer, changing INSTALL_DIR, without sudo:

curl -sSL https://bit.ly/install-xq | INSTALL_DIR=$(pwd) bash

For Ubuntu 22.10 or higher via package manager:

apt-get install xq

For Fedora via package manager:

dnf install xq

A more detailed list of Linux distros that package the xq utility can be found here: https://repology.org/project/xq-sibprogrammer/versions

If you have Go toolchain installed, you can use the following command to install xq:

go install github.com/sibprogrammer/xq@latest

You can play with the xq utility using the Dockerized environment:

docker compose run --rm xq
xq /opt/examples/xml/unformatted.xml
Related repositories
ohmyzsh/ohmyzsh

🙃 A delightful community-driven (with 2,500+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool that makes it easy to keep up with the latest updates from the community.

ShellMIT Licenseshellzsh-configuration
ohmyz.sh
188.7k26.5k
microsoft/terminal

The new Windows Terminal and the original Windows console host, all in the same place!

C++MIT Licenseconsoleterminal
104.3k9.4k
jesseduffield/lazygit

simple terminal UI for git commands

GoGo ModulesMIT Licensecligit
80.6k2.9k
Eugeny/tabby

A terminal for a more modern age

TypeScriptnpmMIT Licenseterminal-emulatorsterminal
tabby.sh
73.4k4.2k
alacritty/alacritty

A cross-platform, OpenGL terminal emulator.

Rustcrates.ioApache License 2.0terminal-emulatorsopengl
alacritty.org
65k3.5k
warpdotdev/warp

Warp is an agentic development environment, born out of the terminal.

Rustcrates.ioGNU Affero General Public License v3.0rustlinux
warp.dev
63.5k5.3k
tldr-pages/tldr

Collaborative cheatsheets for console commands 📚.

MarkdownOthershellman-page
tldr.sh
63.2k5.3k
sharkdp/bat

A cat(1) clone with wings.

Rustcrates.ioApache License 2.0command-linetool
59.8k1.6k
termux/termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.

JavaMavenOtherandroidterminal
f-droid.org/en/packages/com.termux
57.9k7k
Textualize/rich

Rich is a Python library for rich text and beautiful formatting in the terminal.

PythonPyPIMIT Licensepythonpython3
rich.readthedocs.io/en/latest/
56.9k2.3k
GitSquared/edex-ui

A cross-platform, customizable science fiction terminal emulator with advanced monitoring & touchscreen support.

JavaScriptnpmGNU General Public License v3.0terminalscience-fiction
45k3.2k
vercel/hyper

A terminal built on web technologies

TypeScriptnpmMIT Licenseterminaljavascript
hyper.is
44.7k3.6k