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

时间:2015-05-06 09:43:52

标签: xquery

以下内容之间有什么区别:

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

“import module namespace”与“declare namespace”相比如何?

更重要的是,使用命名空间decalaration waht是

之间的区别
declare namespace an =  "http://zorba.io/annotations";

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

1 个答案:

答案 0 :(得分:3)

模块命名空间允许您使用各种模块的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']

将查询具有“x”命名空间的xml元素。

现在关于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;

和zorba仍然能够理解它。

相关问题