Changes

Jump to navigation Jump to search
119 bytes added ,  15:36, 27 February 2020
no edit summary
Database nodes are XML nodes which are either stored in a persistent database, or which are a node of a main-memory database representation. XML fragments can be converted to a main-memory database by e. g. applying the [[XQuery_Update#update|update]] or [[XQuery_Update#transform|transform]] expression on a node:
<pre classsyntaxhighlight lang="brush:xquery">
db:node-id(element hello { 'world' } update {})
</presyntaxhighlight>
=General Functions=
|Exports the specified database {{Code|$db}} to the specified file {{Code|$path}}. Existing files will be overwritten. The {{Code|$params}} argument contains serialization parameters (see [[Serialization]] for more details), which can either be specified<br />
* as children of an {{Code|&lt;output:serialization-parameters/&gt;}} element, as defined for the [http://www.w3.org/TR/xpath-functions-30/#func-serialize fn:serialize()] function; e.g.:
<pre classsyntaxhighlight lang="brush:xml">
<output:serialization-parameters>
<output:method value='xml'/>
...
</output:serialization-parameters>
</presyntaxhighlight>
* as map, which contains all key/value pairs:
<pre classsyntaxhighlight lang="brush:xml">
map { "method": "xml", "cdata-section-elements": "div", ... }
</presyntaxhighlight>
|-
| '''Errors'''
| '''Examples'''
| Export all files as text:<br/>
<pre classsyntaxhighlight lang="brush:xquery">
db:export("DB", "/home/john/xml/texts", map { 'method': 'text' })
</presyntaxhighlight>
The following query can be used to export parts of the database:
<pre classsyntaxhighlight lang="brush:xquery">
let $target := '/home/john/xml/target'
for $doc in db:open('DB', 'collection')
file:write($path, $doc)
)
</presyntaxhighlight>
|}
* {{Code|db:replace("DB", "docs/dir/doc.xml", document { <a/> })}} replaces the content of the document {{Code|docs/dir/doc.xml}} in the database {{Code|DB}} with the specified document node.
The following query can be used to import files from a directory to a database:
<pre classsyntaxhighlight lang="brush:xquery">
let $source := '/home/john/xml/source'
for $file in file:list($source, true())
where not(file:is-dir($path))
return db:replace('db', $file, doc($path))
</presyntaxhighlight>
|}
* {{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 classsyntaxhighlight lang="brush:xquery">
let $db := 'db'
let $src-path := 'src/'
let $trg := $trg-path || substring-after($src, $src-path)
return db:store($db, $trg, db:retrieve($db, $src))
</presyntaxhighlight>
|}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu