collections - Zorba 系列 : a simple directory of xml files

标签 collections xquery zorba

我有一个 xml 文件目录,我想将其用作集合,特别是查看 $my_collection/of/things每个文件都有 <things> .

我正在使用 Zorba。

这导致 error retrieving resource (语法问题?):

variable $my_collection := fn:collection("file://localhost/path/to/my/*.xml");

我还阅读了 Zorba 的文档 Data Definition Facility ...对于这个单一的目的来说似乎有点矫枉过正。或者,不是?

最佳答案

已编辑的问题 - 将所有内容放入实际的 Zorba 集合中,而不是节点列表。您可能希望根据您的目的在静态和动态集合之间进行选择。

F.xq:

module namespace X = "urn:xml-files";
import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
import module namespace file = "http://expath.org/ns/file";
import module namespace x = "http://www.zorba-xquery.com/modules/xml";
declare namespace ann = "http://www.zorba-xquery.com/annotations";

declare collection X:files as node()*;
declare variable $X:uri := xs:QName('X:files');

declare %ann:nondeterministic function X:get-xml-list($dir-name as xs:string) {
    let $files := file:list($dir-name, true())
    for $filename in $files
    where ends-with($filename, ".xml")
    return $filename
};
declare %ann:sequential function X:load-files($names as xs:string*) {
    ddl:create($X:uri);
    dml:insert-nodes($X:uri, for $filename in $names return x:parse(file:read-text($filename),()));
};
declare %ann:sequential function X:load-directory($dir-name as xs:string) {
    X:load-files(X:get-xml-list($dir-name))
};

x.xq:

xquery version "3.0" encoding "utf-8";
import module namespace X = "urn:xml-files" at "F.xq";
import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
X:load-directory("C:\Projects-dir...-with-xmls\");
dml:collection($X:uri)

引用资料:

关于collections - Zorba 系列 : a simple directory of xml files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19325230/

相关文章:

C++ XQuery 引擎 - zorba 或 XQilla 或其他

node.js - 如何在mongodb中查找一个对象

xml - TSQL XML 将节点值转换为 int

c# - 需要一些关于 HashSet 工作原理的解释

xquery - 如何找到为回答我的 Xquery 查询而访问的文档?

xpath - 如何在LibXml 2中使用Xpath

java - Zorba XQuery 更新工具直接修改 XML 文件

JSONiq:Java 实现作为库?

delphi - 如何更新 TList<T> 中的数据?

java - 是否可以将不可变列表作为 Java 中不可变映射内的值字段?