Xquery 如何在不创建数据库的情况下访问BaseX中的文件?

Xquery 如何在不创建数据库的情况下访问BaseX中的文件?,xquery,basex,Xquery,Basex,我需要根据BaseX命令行工具的-I选项提供的上下文转换一些XML文件: $ basex --help BaseX 8.4.2 [Standalone] Usage: basex [-bcdiIoqrRstuvVwxXz] [input] [input] XQuery or command file, or query string -b<pars> Bind external query variables -c<input> Execut

我需要根据BaseX命令行工具的
-I
选项提供的上下文转换一些XML文件:

$ basex --help
BaseX 8.4.2 [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
$basex--帮助
BaseX 8.4.2[独立]
用法:basex[-bcdiioqrrstuvwxxz][input]
[输入]XQuery或命令文件,或查询字符串
-b绑定外部查询变量
-c从文件或字符串执行命令
-d激活调试模式
-我将文件或数据库分配给上下文
-我将输入字符串分配给上下文
-o将输出写入文件
-q执行XQuery表达式
-r设置查询执行的次数
-R打开/关闭查询执行
-设置序列化参数
-t[path]在文件或目录中运行测试
-u将更新写回原始文件
-v/v显示(全部)流程信息
-w保留输入文件中的空白
-x显示查询计划
-X显示编译前/编译后的查询计划
-z跳过结果的输出
我不想使用数据库,因为我需要显式地创建数据库。我是否可以使用
basex-I context.xml test.xqy
将上下文与转换结合起来,并且在
test.xqy
文件中,我是否可以使用类似
doc(“上下文”)的东西直接访问
context.xml
? 是否有其他XQuery处理器提供此功能?

在不创建数据库的情况下访问文件 我不想使用数据库,因为我需要显式地创建数据库。我可以使用basex-I context.xml test.xqy将上下文与转换结合起来吗?在test.xqy文件中,我可以直接使用doc(“context”)之类的东西访问context.xml吗

对于临时查询,最简单的方法是在
doc(…)
函数中传递文档。在BaseX中,
doc(…)
函数可用于访问数据库、本地文件甚至远程URI,如BaseX文档一章中所述。如果名称与数据库名称不匹配,BaseX将尝试打开具有此名称的文件。您还可以提供
doc(…)
函数的相对或绝对路径

实际上,这会创建文件的内存数据库表示形式(这对于合理的性能是必要的,文本XML实际上不适合快速计算查询),但这是透明的(但需要将文档放入主内存)

例如,要计算工作目录中存储的
context.xml
文件中的元素数,请运行

count(doc('context.xml')//*)
更新文件 我需要转换一些XML文件[…]

在以这种方式打开的XML文件上也可以这样做,但请确保,使用
-u
参数也可以:

-u          Write updates back to original files

如果通过-i指定XML文件,则无需在查询中使用
doc('context')
。文件将绑定到所谓的“上下文项”,您可以通过
直接访问它(例如:
count(./*)