2013-02-02 54 views
0

我不知道Xquery如何在服務器上工作。我知道語法,但不知道如何爲我的網站實施它。Xquery如何在服務器上工作

例如。我有網站存儲在XML文件的用戶名和密碼。現在我想驗證用於登錄或註冊的用戶名和密碼。

我該怎麼做?我只寫一個Xquery文件並上傳到服務器然後調用它?

+0

您使用的是什麼XQuery處理器?那裏有很多,最重要的支持REST或RestXQ,例如BaseX,eXist和MarkLogic。特別是RestXQ適合編寫服務器端XQuery。 – dirkk

+0

我正在使用Sausalito。服務器端Xquery是什麼意思? – Michael

回答

1

請在下面找到一個在Sausalito上運行的基本認證模塊的例子。

module namespace auth = "[project logical uri]lib/auth"; 

import module namespace base64 = "http://www.zorba-xquery.com/modules/converters/base64"; 

import module namespace req = "http://www.28msec.com/modules/http/request"; 
import module namespace res = "http://www.28msec.com/modules/http/response"; 

declare variable $auth:login := "login"; 
declare variable $auth:password := "password"; 

declare function auth:authorize() as empty-sequence() 
{ 
let $auth := "Basic " || string(base64:encode($html:login || ":" || $html:password)) eq req:header-value("Authorization") 
return 
    if(not($auth) and not($unprotected)) then 
    error($res:unauthorized); 
    else 
    (); 
}; 
+0

謝謝。所以我有這樣一個Xquery文件,然後將文件上傳到服務器。 – Michael

相關問題