Skip to content
/ xq Public
forked from sibprogrammer/xq

Command-line XML and HTML beautifier and content extractor

License

Notifications You must be signed in to change notification settings

nworms/xq

 
 

Repository files navigation

xq

build Go Report Card Codecov 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

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"

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 Ubuntu 22.10 or higher via package manager:

apt-get install xq

For Fedora via package manager:

dnf install xq

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

go install github.com/sibprogrammer/xq@latest

About

Command-line XML and HTML beautifier and content extractor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 89.0%
  • HTML 7.2%
  • Shell 3.8%