Collections Zorba集合:xml文件的简单目录

Collections Zorba集合:xml文件的简单目录,collections,xquery,zorba,Collections,Xquery,Zorba,我有一个xml文件目录,我想用它作为一个集合,特别是查看$my_collection/of/things,其中每个文件都有 我正在使用Zorba 这会导致检索资源时出错(语法问题?) 变量$my\u collection:=fn:collection(“file://localhost/path/to/my/*.xml”) 我还阅读了关于Zorba的文档。。。为了这个特殊的目的,似乎有点过分了。或者,不是吗?尝试使用 collection("file:///localhost/path/to/m

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

我正在使用Zorba

这会导致检索资源时出错(语法问题?)

变量$my\u collection:=fn:collection(“file://localhost/path/to/my/*.xml”)

我还阅读了关于Zorba的文档。。。为了这个特殊的目的,似乎有点过分了。或者,不是吗?

尝试使用

collection("file:///localhost/path/to/my?select=*.xml;recurse=yes")

编辑问题-将所有内容放入实际的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))
};
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)
x.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))
};
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)
参考资料:


用户Scala William添加的解决方案是可行的,但他的解决方案有点过时。以下是他为zorba 3.0更新的代码:

F.xq

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

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

declare %an:nondeterministic function X:get-xml-list($dir-name as xs:string)
{
    let $files := fs:list($dir-name, fn:false(),"*.xml")
    for $filename in $files
    return concat($dir-name,$filename)
};

declare %an:sequential function X:load-files($names as xs:string*)
{
    ddl:create($X:uri);
    dml:insert($X:uri, for $filename in $names return x:parse(fs:read-text($filename),()));
};

declare %an:sequential function X:load-directory($dir-name as xs:string)
{
    X:load-files(X:get-xml-list($dir-name))
};
请注意,在X:get-xml-list()的返回中调用了concat(…),而不是$filename。此外,对插入节点(…)的调用已更改为在X:load-files()处插入(…)


也请考虑在FS:FLUT:FUL:TURE()中更改FN:List:(…)在x:GET-XML-()中,如果需要列表递归。p> 使用Saxon,我只说

声明变量$my_collection:=collection(“/path/to/my/xml_directory”)
Zorba也会为此返回“检索资源时出错”。我可以用这个从Zorba获取
检索资源时出错。我知道这条路没有错,因为撒克逊人也有同样的路;相反,
collection
应该从每个文件中读取节点树并绑定到单个变量,就好像它首先是一个大文件一样。嗨@Pete,这就是你想要的吗?我编辑过-现在所有的东西都被加载到一个集合中。+1个关于如何使用Zorba集合实现这一目标的好例子。问题仍然是,是否需要Zorba收集?或者有什么方法可以像我们使用萨克森一样获得一行程序集?嗨,我使用的是Zorba3.1。我收到以下错误:
:3,1:静态错误[err:XQST0059]:模块“http://www.zorba-xquery.com/modules/store/static/collections/dml“在位置上找不到”http://www.zorba-xquery.com/modules/store/static/collections/dml" : "http://www.zorba-xquery.com/modules/store/static/collections/dml.module":无法创建流资源