在 XQuery 中导入和声明模块名称空间的区别?

Difference between importing and declaring module namespace in XQuery?

以下有什么区别:

import module namespace fs = "http://expath.org/ns/file";
declare namespace an = "http://zorba.io/annotations";

"import module namespace" 与 "declare namespace" 相比如何?

此外,命名空间声明之间的区别是什么

declare namespace an =  "http://zorba.io/annotations";

module namespace an =  "http://zorba.io/annotations";

模块命名空间将允许您使用来自不同模块的 xquery 函数。这就像使用其他语言的库一样。例如 functx 库:

import module namespace functx="http://www.functx.com"

functx:substring-before-match('abc-def-ghi', '[dg]')

如果您想创建自己的模块,'mymodule.xq'您将以模块声明开始文件:

module namespace mymodule = "http://example.org/mymodule";

declare function mymodule:myfunc()....

声明命名空间允许您使用不同的命名空间创建和查询 xml 元素。

例如:

declare namespace x="http://some.random.namespace"; 
//x:someelement[. = 'hello world']

将查询 xml 个具有 'x' 命名空间的元素。

现在是关于 zorba 注释的情况。声明一个命名空间实际上只是对 xquery 处理器说:这个前缀 (an) 绑定到这个命名空间 (http://zorba.io/annotations)。我不太确定如何进一步解释它,它只是它在 xquery 规范中定义的方式。它只是告诉 xquery 处理器如果你输入:

declare %an:nondeterministic function random:random() as xs:integer external;

'an' 绑定到“http://zorba.io/annotations”,这是 zorba 会理解的内容。

您也可以将 'an' 更改为 'foo':

declare namespace foo =  "http://zorba.io/annotations";
declare %foo:nondeterministic function random:random() as xs:integer external;

左巴人仍然能够理解它。