我有一个 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/