5
votes

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"".

4
See the getting started section of the Saxon documenation saxonica.com/html/documentation/about/gettingstarted/… .chrisis
If you clean up your question a bit, this could actually be a very useful question, given the diversity of the projects described below. I'd suggest adding the precise command you ran that generated the error, and maybe improve the pseudo command you'd like to be able to use.Joe Wicentowski
The title cannot be replicated. On the basis of the title alone I cannot agree more with @joewiz.Thufir
java -cp Saxon-HE.jar net.sf.saxon.Query {1}klaus

4 Answers

10
votes

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

10
votes

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
4
votes

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.

1
votes

eXist offers XQuery 3.1 support and is packaged with scripts for executing queries and accessing the database from the command line:

$ bin/client.sh -s

Using locale: en_US.UTF-8
eXist version 3.3.0-SNAPSHOT (00c8bb256), Copyright (C) 2001-2017 The eXist-db Project
eXist-db comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; for details read the license file.

Connecting to database...
Connected :-)

type help or ? for help.

exist:/db>help
--- general commands ---
ls                   list collection contents
cd [collection|..]   change current collection
put [file pattern]   upload file or directory to the database
putgz [file pattern] upload possibly gzip compressed file or directory to the database
putzip [file pattern] upload the contents of a ZIP archive to the database
edit [resource] open the resource for editing
mkcol collection     create new sub-collection in current collection
rm document          remove document from current collection
rmcol collection     remove collection
set [key=value]      set property. Calling set without 
                     argument shows current settings.

--- search commands ---
find xpath-expr      execute the given XPath expression.
show [position]      display query result value at position.

--- user management (may require dba rights) ---
users                list existing users.
adduser username     create a new user.
passwd username      change password for user. 
chown user group [resource]
                     change resource ownership. chown without
                     resource changes ownership of the current
                     collection.
chmod [resource] permissions
                     change resource permissions. Format:
                     [user|group|other]=[+|-][read|write|execute].
                     chmod without resource changes permissions for
                     the current collection.
lock resource        put a write lock on the specified resource.
unlock resource      remove a write lock from the specified resource.
svn                  subversion command-line client.
threads              threads debug information.
quit                 quit the program

See also Using the Command-line Client and Executing Queries from the eXist documentation.