Thanks to visit codestin.com
Credit goes to github.com

Skip to content

linkdd/xq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Query XML data using XPath

Topics

Resources

License

Stars

Watchers

Forks

Languages