2015-05-06 77 views
1

是什麼下面的區別:在XQuery中導入和聲明模塊名稱空間的區別?

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

如何「進口模塊命名空間」比較「申報命名空間」?

而更多了,與命名空間decalaration是啥子

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

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

回答

2

模塊命名空間之間的區別,您就可以使用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; 

那是一個「必然「http://zorba.io/annotations」這是一件好事左巴就明白了。

你還不如改變「的」到「富」:

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

和左巴仍然能夠理解它。

+0

嘿,謝謝你的回答。我得到的導入模塊類似於使用庫。但是我仍然不確定**聲明名稱空間**在做什麼。我更詳細地提出了我的問題。 – SteveCallender

+0

更新了我的答案,希望這是有道理的;) –

+0

很好的描述,謝謝。 – SteveCallender

相關問題