2013-05-18

xqillac

xqillac is a fork of the xqilla command-line XQuery processor to.. make it work better from the command line. XQuery is a language for searching and editing XML; a superset of XPath.

For example, let's say you have some XML coming along a shell pipeline:

<a>
  <b id="5">hello</b>
  <b id="7">world</b>
</a>

..and you want just the 5th b's text:

$ printf '<a><b id="5">hello</b><b id="7">world</b></a>' |
    xqilla -i /dev/stdin <(echo "data(//b[@id='5'])")
hello

Groovy. Much safer than trying to do this kind of thing with regexes or cut or whatever.

However, as you can see, this involves horrible abuse of the shell "<(" operator (which turns a command's output into a file (..well, close enough, right?)), and of /dev/stdin.

In xqillac, this is just:

printf '<a><b id="5">hello</b><b id="7">world</b></a>' |
    xqillac "data(//b[@id='5'])"

The above shell hack also fails (horribly: "Caught unknown exception"... or worse) if you attempt to use XQuery Update to edit the document in the pipeline:

xqillac allows this (for documents that fit in memory):

$ printf '<a><b id="5">hello</b><b id="7">world</b></a>' |
    xqillac "delete nodes //b[@id='5']"
<a><b id="7">world</b></a>

Code on xqillac's github. Please use the Github functionality for issues and pull requests.


In addition, I've fixed various other things I consider massive bugs:

  • Various error messages actually get handed to the user, instead of being thrown on the floor
  • Option (enabled by default when invoked as xqillac) to disable going to the Internet to attempt to "resolve" DTDs/namespaces. It just boggles me that a library would try to do that, and that it's a nasty hack to disable this horrible behaviour.

You can use xqillac as xqilla too, just symlink it.

Build instructions:

  1. Run make.
  2. Celebrate.

It depends on libxqilla-dev.


Commenting is disabled for this post.

Read more of Faux' blog