创建一个简单的文档

这个非常简单的 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>

既然文档存在,我们可以测试其他操作……