我有一个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)
参考文献:
http://www.zorba.io/documentation/2.9/zorba/xqddf.html
http://en.wikipedia.org/wiki/Zorba_(XQuery_processor)
http://www.w3.org/TR/xpath-functions-30/#func-ends-with
http://www.zorba.io/documentation/2.9/modules/expath.org_ns_file.html
create collection, add document to zorba using command line?