Sibprogrammer/xq: Command Line XML Beautifier And ... - GitHub
Command-line XML and HTML beautifier and content extractor.

- Syntax highlighting
- Automatic indentation and formatting
- Automatic pagination
- Node content extraction
Format an XML file and highlight the syntax:
xq test/data/xml/unformatted.xmlxq also accepts input through stdin:
curl -s https://www.w3schools.com/xml/note.xml | xqHTML content can be formatted and highlighted as well (using -m flag):
xq -m test/data/html/formatted.htmlIt 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 //cityExtract the value of attribute named status and belonging to user:
cat test/data/xml/unformatted.xml | xq -x /user/@statusSee 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 -jThis 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
The preferable ways to install the utility are described below.
For macOS, via Homebrew:
brew install xqFor macOS, via MacPorts:
sudo port install xqFor Linux using custom installer:
curl -sSL https://bit.ly/install-xq | sudo bashFor Linux using custom installer, changing INSTALL_DIR, without sudo:
curl -sSL https://bit.ly/install-xq | INSTALL_DIR=$(pwd) bashFor Ubuntu 22.10 or higher via package manager:
apt-get install xqFor Fedora via package manager:
dnf install xqA 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@latestYou can play with the xq utility using the Dockerized environment:
docker compose run --rm xq xq /opt/examples/xml/unformatted.xmlTừ khóa » Xq Github
-
Xq - Like Jq, But For XML And XPath. - GitHub
-
MiSawa/xq: Pure Rust Implementation Of Jq - GitHub
-
Sbowman/xq - GitHub
-
Xq/ At Master · Sibprogrammer/xq - GitHub
-
Xq - Command-line XPath Processor For HTML And XML - GitHub
-
Chanwit/xq: Any Configuration Processor - GitHub
-
Xq · GitHub Topics
-
Luolong/xq: Siple Command Line Utility To Filter XML Content - GitHub
-
Go-xq · GitHub Topics
-
Spali/go-xq: XML Query Utility To Extract Xml From A File, Input ... - GitHub
-
- Command-line XML Processor Inspired By `jq` - GitHub
-
Xq/ At Master · Tfussell/xq - GitHub
-
Kislyuk/yq - Jq Wrapper For YAML/XML/TOML Documents - GitHub
-
Mustache - GitHub