如何将XQuery的结果存储在数据库中?

时间:2014-05-21 03:46:29

标签: xml xpath xquery exist-db

我有以下.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

1 个答案:

答案 0 :(得分: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)