Changes

Jump to navigation Jump to search
631 bytes added ,  11:24, 20 March 2017
==Database Nodes==
Database nodes are XML nodes which are either stored in a persistent database , or part of which contained in a so-called ''database fragment''. All XML fragments can be converted to database fragments by e. g. applying the [[XQuery_Update#transform|transform]] expression on an XML fragment:
<pre class="brush:xquery">
* {{Code|db:retrieve("DB", "music/01.mp3")}} returns the specified audio file as raw data.
* <code><nowiki>stream:materialize(db:retrieve("DB", "music/01.mp3"))</nowiki></code> materializes the streamable result in main-memory before returning it.
* <code><nowiki>convert:binary-to-string(db:retrieve("DB", "info.txt"), 'UTF-8')</nowiki></code> converts a binary database resource as UTF-8 text and returns a string.
|}
| '''Examples'''
|
* {{Code|<code>db:add("DB", "/home/dir/doc.xml")}} </code> adds the file {{Code|/home/dir/doc.xml}} to the database {{Code|DB}}.* {{Code|<code>db:add("DB", <a/>, "doc.xml")}} </code> adds a document node to the database {{Code|DB}} under the name {{Code|doc.xml}}.* {{Code|<code>db:add("DB", "/home/dir", "docs/dir", map { 'addcache': true()}} )</code> adds all documents in {{Code|/home/dir}} to the database {{Code|DB}} under the path {{Code|docs/dir}}. In order to reduce memory consumption, the files will be cached before being added to the database.
|}
|-
| width='120' | '''Signatures'''
|{{Func|db:alter|$db as xs:string, $newname name as xs:string|empty-sequence()}}
|-
| '''Summary'''
|Renames the database specified by {{Code|$db}} to {{Code|$newnamename}}.
|-
| '''Errors'''
|
* {{Code|db:store("DB", "video/sample.mov", file:read-binary('video.mov'))}} stores the addressed video file at the specified location.
* With the following query, you can copy full directories:
<pre class="brush:xquery">
let $db := 'db'
let $src-path := 'src/'
let $trg-path := 'trg/'
for $src in db:list($db, $src-path)
where db:is-raw($db, $src)
let $trg := $trg-path || substring-after($src, $src-path)
return db:store($db, $trg, db:retrieve($db, $src))
</pre>
|}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu