Command line XML beautifier and content extractor. Similar to jq.

xq

Command line XML beautifier and content extractor. Similar to jq.

xq

Features

  • Syntax highlighting
  • Automatic indentation
  • Node content extraction

Installation

A simple way to install the utility is to use the curl and bash installer.

For macOS:

curl -sSL https://git.io/JXZHK | bash

For Linux:

curl -sSL https://git.io/JXZHK | sudo bash

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

go install github.com/sibprogrammer/xq@latest
Owner
Comments
  • HTML Multiline comments

    HTML Multiline comments

    Small thing I noticed, for HTML multiline comments the first line gets indented, the other lines stay. Maybe multiline comments should be ignored

    raw

    <body>
    <!--
      <p>hello</p>
    -->
    <p>world</p>
    </body>
    

    formatted

      <body>
        <!--
      <p>hello</p>
    -->
        <p>world</p>
      </body>
    
    
  • Space removed between tag and bracket

    Space removed between tag and bracket

    With file.html with content:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title></title>
    </head>
    <body>
      <p><b>blah</b> (blah)</p>
    </body>
    </html>
    
    $ xq -m file.html | grep blah
          <b>blah</b>(blah)</p>
    

    Note the space is removed between the closing b tag and the opening bracket. This changes the meaning of the content.

  • Breaks namespaces

    Breaks namespaces

    Input:

    <?xml version="1.0" encoding="UTF-8"?> 
    <iris1:request xmlns:iris1="urn:ietf:params:xml:ns:iris1"> 
      <iris1:searchSet> 
        <iris1:lookupEntity registryType="dchk1" entityClass="domain-name" entityName="ficora.fi"/> 
      </iris1:searchSet> 
    </iris1:request>
    

    Output:

    <?xml version="1.0" encoding="UTF-8"?>
    <request iris1="urn:ietf:params:xml:ns:iris1">
      <searchSet>
        <lookupEntity registryType="dchk1" entityClass="domain-name" entityName="ficora.fi">
        </lookupEntity>
      </searchSet>
    </request>
    
  • XML files with non-utf encoding are not parsed properly

    XML files with non-utf encoding are not parsed properly

    Sample xml:

    <?xml version="1.0" encoding="windows-1251"?>
    <xml></xml>
    

    ./xq test.xml produces error Error: xml: encoding "windows-1251" declared but Decoder.CharsetReader is nil

  • CSS Selectors Support

    CSS Selectors Support

    Problem Statement

    The XPath query language is less popular and more verbose compared to CSS selectors.

    Expected Result

    It is possible to query content using a CSS selector.

    Additional Info

    The corresponding thread: https://news.ycombinator.com/item?id=33573240

  • Automatic Detection of XML vs HTML

    Automatic Detection of XML vs HTML

    Problem Statement

    Right now one needs to specify -m flag if HTML input is provided instead of XML. It seems it's possible to implement heuristic algorithm to autodetect the input type.

    Expected Result

    Autodetection of content type is implemented. No need to provide -m flag in most cases.

  • HTML Formatter

    HTML Formatter

    Problem Statement

    It's quite helpful to highlight HTML content, but usually this content is not a valid XML.

    Expected Result

    An ability to highlight HTML is introduced.

  • Disable colorful output

    Disable colorful output

    Problem Statement

    Under certain circumstances, the only formatted output is needed without syntax highlighting. E.g. the terminal does not support colors.

    Expected Result

    An option to disable the colorful output is introduced.

    xq --no-color ./test/data/formatted.xml
    
  • Shortcut to extract only one node from XML

    Shortcut to extract only one node from XML

    Problem Statement

    The way to extract only a single node using XPath is not so obvious and requires additional typing. Usually, I needed in the first node of the set.

    Expected Result

    A shortcut to extract only the first node. Here is an example:

    cat file.xml | xq -e //item/title
    

    The output will contain the first match of the XPath expression.

    Additional info

    Workaround 1:

    cat file.xml | xq -x "(//item/title)[1]"
    

    Workaround 2:

    cat file.xml | xq -x "//item/title" | head -1
    
  • Control chars instead of colors with

    Control chars instead of colors with "less" on Linux

    Problem Statement

    If "less" is defined as $PAGER the control character escape sequences are rendered instead of colors on Linux. Due to unclear reasons, there is no such problem with macOS.

    # export PAGER=less ; curl -s https://www.w3schools.com/xml/note.xml | xq
    ESC[33m<?ESC[0mxml version="1.0" encoding="UTF-8"ESC[33m?>ESC[0m
    ESC[33m<noteESC[0mESC[33m>ESC[0m
      ESC[33m<toESC[0mESC[33m>ESC[0mToveESC[33m</to>ESC[0m
      ESC[33m<fromESC[0mESC[33m>ESC[0mJaniESC[33m</from>ESC[0m
      ESC[33m<headingESC[0mESC[33m>ESC[0mReminderESC[33m</heading>ESC[0m
      ESC[33m<bodyESC[0mESC[33m>ESC[0mDon't forget me this weekend!ESC[33m</body>ESC[0m
    ESC[33m</note>ESC[0m
    

    Expected Result

    The colorful output is expected.

  • PI attribute values are not highlighted

    PI attribute values are not highlighted

    Problem Statement

    The attribute values in processing instructions are not highlighted.

    Expected Result

    The example of PI

    <?xml version="1.0" encoding="UTF-8"?>
    

    It is expected that values like "1.0" and "UTF-8" are highlighted (similar to other attributes processing).

  • Unable to render XML version 1.1.

    Unable to render XML version 1.1.

    Problem Statement

    The utility fails on the attempt to render XML version 1.1.

    Steps to Reproduce

    xq xml-file.xml

    Where xml-file.xml contains the following content:

    <?xml version='1.1' encoding='UTF-8'?>
    <Tag plugin="[email protected]">
        <node class="cps.n.StepStartNode" plugin="[email protected]">
            <parentIds>
                <string>17</string>
            </parentIds>
            <id>18</id>
            <descriptorId>org.jenkinsci.plugins.pipeline.modeldefinition.steps.ScriptStep</descriptorId>
        </node>
        <actions>
            <s.a.LogStorageAction/>
            <wf.a.TimingAction plugin="[email protected]">
                <startTime>1643040131437</startTime>
            </wf.a.TimingAction>
        </actions>
    </Tag>
    
    

    Actual Result

    Error message saying: xml: unsupported version "1.1"; only version 1.0 is supported

    Expected Result

    The file is rendered properly.

    Additional Info

    One of the sources of such files is Jenkins.

  • Snap Support

    Snap Support

    Problem Statement

    For Linux system that supports snap it is more safe and convenient to use it instead of "curl + bash" combination.

    Expected Result

    Snap package for xq is prepared.

Related tags
A twitch focused command line tool for producing, archiving and managing live stream content. Built for Linux.

twinx is a live-streaming command line tool for Linux. It connects streaming services (like Twitch, OBS and YouTube) together via a common title and description.

Oct 17, 2022
Emlparsingtool - A command line tool that extracts attachments and content directly

A command line tool that extracts attachments and content directly from emL file format messages

Sep 6, 2022
A command-line to create a pull request to review the entire content of a Github repository.

Pull Request Me Pull Request Me (PRMe) creates a pull request for the entire content of a Github repository. This is useful to solicit review comments

Nov 2, 2021
A command line tool that builds and (re)starts your web application everytime you save a Go or template fileA command line tool that builds and (re)starts your web application everytime you save a Go or template file

# Fresh Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file. If the web framework yo

Nov 22, 2021
An open-source GitLab command line tool bringing GitLab's cool features to your command line
An open-source GitLab command line tool bringing GitLab's cool features to your command line

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching

Dec 30, 2022
A command line tool to prompt for a value to be included in another command line.

readval is a command line tool which is designed for one specific purpose—to prompt for a value to be included in another command line. readval prints

Dec 22, 2021
Watcher - A simple command line app to watch files in a directory for changes and run a command when files change!

Watcher - Develop your programs easily Watcher watches all the files present in the directory it is run from of the directory that is specified while

Mar 27, 2022
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Jan 8, 2023
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Table of contents Introduction Reference Contributing Introduction Overview git-xargs is a command-line tool (CLI) for making updates across multiple

Dec 31, 2022
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command. You give git-xargs:

Feb 5, 2022
Package command provide simple API to create modern command-line interface

Package command Package command provide simple API to create modern command-line interface, mainly for lightweight usage, inspired by cobra Usage pack

Jan 16, 2022
A command line tool for simplified docker volume command built with go

dockervol A command line tool for simplified docker volume command built with go. Features: Remove anonymous volume (beta) Remove volume by matching n

Dec 18, 2021
Trzsz-go - A simple file transfer tools, similar to lrzsz ( rz / sz ), and compatible with tmux

Trzsz-go - A simple file transfer tools, similar to lrzsz ( rz / sz ), and compatible with tmux

Dec 31, 2022
PretGO - asic cli for format json,html and xml!
 PretGO - asic cli for format json,html and xml!

PretGO So basic cli for format json,html and xml! Table of contents Screenshots Setup Status Contact Screenshots Setup First clone project git clone h

Sep 2, 2022
GitHub CLI extension to preview your markdown similar to the style of GitHub.
GitHub CLI extension to preview your markdown similar to the style of GitHub.

gh markdown-preview GitHub CLI extension to preview your markdown similar to the style of GitHub gh markdown-preview is a GitHub CLI extension to prev

Jan 8, 2023
Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers.
Rclone (

Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers.

Jan 5, 2023
Command-line tool to load csv and excel (xlsx) files and run sql commands
Command-line tool to load csv and excel (xlsx) files and run sql commands

csv-sql supports loading and saving results as CSV and XLSX files with data processing with SQLite compatible sql commands including joins.

Nov 2, 2022
Rclone ("rsync for cloud storage") is a command-line program to sync files and directories to and from different cloud storage providers.
Rclone (

Website | Documentation | Download | Contributing | Changelog | Installation | Forum Rclone Rclone ("rsync for cloud storage") is a command-line progr

Nov 5, 2021
F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely. Written in Go!
F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely. Written in Go!

F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely.

Dec 31, 2022