Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running XQuery on the command line

It sounds like I need some type of XML processor

It looks like theres a program called Saxon which I can use to run XQuery

When I try this websites example I get

Error: Could not find or load main class net.sf.saxon.Query

I don't know how to set up the java package from the saxon package I downloaded.

Id like to know if there is an easier option to be able to run XQuery from the command line other than this java package? All I want to do is process an xml file with commands like "Select where type="something"".

like image 649
Sam Avatar asked Jun 06 '17 00:06

Sam


3 Answers

My Xidel is a command-line XQuery 3.0 tool.

 xidel your-file.xml --xquery 'your-xquery'

But "select where" is not XQuery. XQuery looks like for ... in .. where .. return or //*[..where..], e.g.

xidel your-file.xml -e "//*[@type = 'something']"

With Xidel -e is short for --xpath or --xquery depending on the following argument (XPath is pretty much the same as XQuery if you are not trying to create a new XML document), and if you need " or ' depends if you call it from the bash or cmd console

like image 91
BeniBela Avatar answered Oct 19 '22 21:10

BeniBela


BaseX offers XQuery 3.0 support and is packaged with scripts that encapsulate calling Java, including setting up the classpath:

$ basex --help
BaseX 8.5.3 [Standalone]
Usage: basex [-bcdiIoqrRstuvVwxXz] [input]
  [input]     XQuery or command file, or query string
  -b<pars>    Bind external query variables
  -c<input>   Execute commands from file or string
  -d          Activate debugging mode
  -i<input>   Assign file or database to context
  -I<input>   Assign input string to context
  -o<output>  Write output to file
  -q<expr>    Execute XQuery expression
  -r<num>     Set number of query executions
  -R          Turn query execution on/off
  -s<pars>    Set serialization parameter(s)
  -t[path]    Run tests in file or directory
  -u          Write updates back to original files
  -v/V        Show (all) process info
  -w          Preserve whitespaces from input files
  -x          Show query plan
  -X          Show query plan before/after compilation
  -z          Skip output of results
like image 11
Jens Erat Avatar answered Oct 19 '22 22:10

Jens Erat


It sounds like you're not familiar with running Java applications from the command line. There are two ways forward: learn how to do it, or avoid the problem by finding a way of running XQuery without use of the command line. Let's try to help you with both, and you can choose.

(A) Using the command line

There's basic information on installing and runnning Saxon here:

http://www.saxonica.com/documentation/index.html#!about/gettingstarted/gettingstartedjava

You somehow found a very old version of this page.

Once you've got through the first 4 steps, you're in business. You've done step (1) (Installing Java) - we know that, because otherwise you wouldn't get this error message. You tell us you've done step (2) (downloading the software). It's not clear whether you did step (3) (unzipping it). And you're clearly attempting step (4) - running XQuery from the command line, but it's failing. The message tells us that it's failing because Java is running, but can't find Saxon on the classpath (which is the place where Java looks to find the Saxon entry point, net.sf.saxon.Query

If that doesn't help you, tell us exactly what you did: exactly what files are found where, exactly what you typed on the command line, and exactly what messages you got.

When you've got past that stage, there's more information about the XQuery command line at

http://www.saxonica.com/documentation/index.html#!using-xquery/commandline

(B) Tools that avoid the command line

Saxon doesn't itself provide any graphical user interfaces for running XSLT or XQuery, but there are plenty of tools that do, both commercial and open source, and most of them have Saxon as the underlying XSLT/XQuery engine (or at least offer Saxon as an option). They may not always support the latest version, but initially that's probably not a concern.

The best of these tools are commercial software: two products from vendors that work closely with Saxonica to integrate the product (e.g. by adding debugging capability) are oXygen and Stylus Studio. A cheaper product with less capability is Editix. Most of these probably have free evaluation licenses, so try them out.

The only open source GUI for Saxon that I know of is KernowforSaxon from Andrew Welch. It's great for doing simple things but I think it hasn't been updated for a while.

like image 4
Michael Kay Avatar answered Oct 19 '22 22:10

Michael Kay