BaseX提供XQuery 3.0支持,并附带脚本,封装了调用Java的过程,包括设置类路径:
$ 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
我的Xidel是一款命令行XQuery 3.0工具。
xidel your-file.xml --xquery 'your-xquery'
但是 "select where" 不是 XQuery。XQuery 的语法格式通常为 for ... in .. where .. return
或 //*[..where..]
。
xidel your-file.xml -e "//*[@type = 'something']"
使用 Xidel 时,-e
缩写为 --xpath
或 --xquery
,取决于后面的参数(如果您不想创建新的 XML 文档,则 XPath 基本上与 XQuery 相同)。而如果您需要 "
或 '
取决于您是从 bash 还是 cmd 控制台调用它。
xidel
不支持 XQuery update
:/ BaseX 则可以直接支持(我日常使用 xidel
,但在这种情况下,它并不是最好的工具)。请参考 https://unix.stackexchange.com/a/561018/12574 和 https://dev59.com/fLD2pogBymzxlkE8S_0sxidel-remove-nodes-with-xquery-in-a-shell - Gilles Quénot听起来你不熟悉如何从命令行运行Java应用程序。有两种方法:学习如何做,或者找到一种不使用命令行运行XQuery的方法来避免问题。让我们尝试帮助你解决这两个问题,然后你可以选择。
(A) 使用命令行
关于安装和运行Saxon的基本信息在这里:
http://www.saxonica.com/documentation/index.html#!about/gettingstarted/gettingstartedjava
你不知怎么找到了这个非常旧的页面。http://www.saxonica.com/documentation/index.html#!using-xquery/commandline
(B) 避免使用命令行的工具
Saxon本身没有为运行XSLT或XQuery提供任何图形用户界面,但有许多工具可以做到这一点,无论是商业软件还是开源软件,其中大多数都有Saxon作为底层XSLT/XQuery引擎(或至少提供Saxon作为选项)。它们可能并不总是支持最新版本,但最初这可能并不重要。
这些工具中最好的是商业软件:两个来自与Saxonica密切合作以集成该产品(例如通过添加调试功能)的供应商的产品是oXygen和Stylus Studio。一个具有较少功能但价格更便宜的产品是Editix。这些产品中大多数可能都有免费评估许可证,因此可以试用它们。
我所知道的唯一一个适用于Saxon的开源GUI是Andrew Welch的KernowforSaxon。它非常适合做简单的事情,但我认为它已经有一段时间没有更新了。
eXist 提供XQuery 3.1支持,并附带用于执行查询和从命令行访问数据库的脚本:
$ 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
bin/client.sh
)会处理它。我在您的帖子评论中链接的要点中的 saxonxq
命令为 Saxon 添加了这种新手友好的简单性。 - Joe Wicentowski