xq

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 3 Imported by: 0

README

xq

Query XML data using XPath.

Installation

go install github.com/linkdd/xq@latest

Examples

Dump the whole XML:

virsh net-dumpxml example | xq "/"
<?xml version="1.0"?><network connections="1">
  <name>example</name>
  <uuid>00000000-0000-0000-0000-000000000000</uuid>
  <forward mode="nat">
    <nat>
      <port start="1024" end="65535"></port>
    </nat>
  </forward>
  <bridge name="virbr1" stp="on" delay="0"></bridge>
  <mac address="52:54:00:7c:52:01"></mac>
  <domain name="example.local" localOnly="yes"></domain>
  <dns enable="yes"></dns>
  <ip family="ipv4" address="10.1.1.1" prefix="24">
    <dhcp>
      <range start="10.1.1.2" end="10.1.1.254"></range>
      <host mac="52:54:00:96:7a:ed" name="example-node-0" ip="10.1.1.10"></host>
    </dhcp>
  </ip>
</network>

Dump a specific node:

virsh net-dumpxml example | xq "/network/ip"
<ip family="ipv4" address="10.1.1.1" prefix="24">
  <dhcp>
    <range start="10.1.1.2" end="10.1.1.254"></range>
    <host mac="52:54:00:96:7a:ed" name="example-node-0" ip="10.1.1.10"></host>
  </dhcp>
</ip>

Dump an attribute:

virsh net-dumpxml example | xq "/network/ip/@address"
10.1.1.1

Dump multiple nodes:

virsh dumpxml example-node-0 | xq "/domain/cpu/feature"
<feature policy="require" name="x2apic"></feature>
<feature policy="require" name="hypervisor"></feature>
<feature policy="require" name="lahf_lm"></feature>
<feature policy="disable" name="svm"></feature>

License

This software is released under the terms of the MIT License.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL