2

I have .xq files that I want to run again some XML data sets. Is there a tool that can be used to run Xquery files again XML data in command line on OSX?

I've already read this: How to execute XPath one-liners from shell?

Community
  • 1
  • 1
User
  • 23,729
  • 38
  • 124
  • 207

2 Answers2

3

For BaseX, to evaluate file.xq against the contents in in.xml and write the result to out.xml:

basex -iin.xml -oout.xml file.xq

Much more documentation is available on the wiki.


For Saxon, to perform the same operation:

java net.sf.saxon.Query -s:in.xml -q:file.xq -o:out.xml

Documentation likewise available.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • Thank-you. And for other readers, I just found the instructions to install BaseX here, http://macappstore.org/basex/ – User Dec 10 '15 at 00:45
  • I'm having trouble installing for this to work on command line: http://stackoverflow.com/questions/34191925/how-to-install-basex-for-command-line – User Dec 10 '15 at 01:47
  • Saxon is probably the easiest to install and run if you want to evaluate queries over files from the command line. If you use `brew`, the package `saxon` is a decently recent version (do **not** use `saxon-b`): "`brew install saxon`". – Florent Georges Dec 10 '15 at 12:40
  • @FlorentGeorges: I used `brew install saxon`, but what's next? it only gives me executable `/usr/local/Cellar/saxon/9.7.0.4/bin/saxon` and that gives me back: `Command line option -q is not recognized. Options available: -? -a -catalog -config -cr -diag -dtd -ea -expand -explain -export -ext -im -init -it -l -license -m -nogo -now -o -opt -or -outval -p -pack -quit -r -repeat -s -sa -scmin -strip -t -T -threads -TJ -TP -traceout -tree -u -val -versionmsg -warnings -x -xi -xmlversion -xsd -xsdversion -xsiloc -xsl -xsltversion -y` …any ideas? – msciwoj Mar 23 '17 at 14:59
  • Does it give a `saxon` executable? Interesting. But it seems it gives only access to the XSLT front-end class. So either you use `java` with the proper classpath and class `net.sf.saxon.Query`, or you use the EXPath repository manager, that comes with a better saxon script, being a front-end for both XSLT and XQuery. Go to http://expath.org/files/pkg, download the latest `expath-repo-installer-*.jar` and execute it. Add the dir `bin/` where it has been installed to your PATH, and you're good to go! – Florent Georges Mar 24 '17 at 14:33
  • @msciwoj - Just posted the above comment as an additional answer, for clarity. – Florent Georges Mar 24 '17 at 14:43
0

If you like packaged bundles, you might be interested by the EXPath repository manager. It comes with Saxon and Calabash (you can pick which to install), as well as scripts to run them with proper classpath, class, etc. It comes with a graphical installer.

To install it:

  • go to http://expath.org/files/pkg
  • download the latest expath-repo-installer-*.jar
  • execute it (e.g. java -jar ~/Downloads/expath-repo-installer-*.jar)
  • (optional) add the dir bin/ where it has been installed to your PATH

On the shell, just invoke saxon --help (or ~/expath/pkg/bin/saxon --help or any ther place you installed it if you did not put it in the PATH), and follow the instructions. All options like --xxx at the beginning of the command line are consumed by the script itself. All the rest is passed as is to Saxon.

For instance to execute a query from the command line, with a specific document as the context item:

saxon --xq -s:data.xml -q:query.xq
Florent Georges
  • 2,190
  • 1
  • 15
  • 24