2014-05-21 17 views
-1

我有以下.xquery文件。如何在數據庫中存儲XQuery的結果?

xquery version "3.0"; 
declare namespace xmldb="http://exist-db.org/xquery/xmldb"; 
(: the output will be presented as html :) 
declare option exist:serialize "method=html media-type=text/html indent=yes"; 

let $something:="" 

return 
    <html> 
     <head>Stackoverflow rocks!</head> 
     <body> 
     <div> 
      <h1>HELLO WORLD!</h> 
     </div> 
     </body> 
    </html> 

我如何綁定返回HTML頁面$variable以存儲它使用這個表達式:

let $store:=xmldb:store('/db/apps/mycollection','page.html',$variable) 
return 
    $store 

回答

3

如何像下面這樣(未測試)?

xquery version "3.0"; 
declare namespace xmldb="http://exist-db.org/xquery/xmldb"; 
(: the output will be presented as html :) 
declare option exist:serialize "method=html media-type=text/html indent=yes"; 

let $doc := 
    <html> 
     <head>Stackoverflow rocks!</head> 
     <body> 
     <div> 
      <h1>HELLO WORLD!</h> 
     </div> 
     </body> 
    </html>, 

    $store := xmldb:store('/db/apps/mycollection', 
          'page.html', 
          $doc) 
return if ($store eq '') then 
    'Sorry, attempted to store document but failed.' 
else 
    concat('Stored document at ', $store) 
+0

上面將把文檔存儲爲'application/xml',eXist會將它添加到它的DOM並對其進行索引,這很可能是我們想要的。然而,如果你想將它存儲在eXist中,就像HTML(文本)一樣,沒有eXist真的做任何特殊的事情,你可以使用'xmldb:store('/ db/apps/mycollection', 'page.html', $ doc'' text/html') – adamretter

+0

它工作得很好。謝謝@C。 M. Sperberg-McQueen。過去我曾爲xml文件做過這樣的事情,但這種「方法」並沒有超越我的想法。傻我。 – loveMeansNothing

相關問題