建立一個簡單的文件

這個非常簡單的 XQuery 片段可以使用內建的 Documents 資料庫作為沙箱在 QueryConsole 中執行。每個片段都有一個註釋來解釋以下程式碼行的含義。

xquery version "1.0-ml";
(: Let's first insert a simple document to get started :)
(: You need a URI- the location where the document is found in the database :)
let $uri := "/stuff/mysimpledocument.xml"
(: Documents need content. This is a simple XML node :)
let $doc := 
  <my-document>
    <body>Very simple example</body>
  </my-document>
(: Permissions are a big topic. For now, we'll use the default permissions. :)
let $permissions := xdmp:default-permissions()
(: Document collections are optional. One or more can be specified :)
(: Adding a collection for further examples that will use it. :)
let $collections := "simple-example"
(: Now we're just going to insert this document in the database :)
let $insert := xdmp:document-insert($uri,$doc,$permissions,$collections)
return <message>Document saved to {$uri}</message>

執行此操作時,控制檯返回

<message>Document saved to /stuff/mysimpledocument.xml</message>

既然文件存在,我們可以測試其他操作……