Changes

Jump to navigation Jump to search
72 bytes removed ,  18:36, 1 December 2023
m
Text replacement - "<syntaxhighlight lang="xquery">" to "<pre lang='xquery'>"
Fragments require less memory for small XML structures, but database nodes are more efficient for larger amounts of data. Fragments nodes can be converted to database nodes by applying a [[XQuery_Update#Main-Memory Updates|main-memory update]] with an empty body to a node:
<syntaxhighlight pre lang="'xquery"'>
<xml>hello world</xml> update { }
</pre>
| '''Examples'''
| Export all files as text:<br/>
<syntaxhighlight pre lang="'xquery"'>
db:export("DB", "/home/john/xml/texts", map { 'method': 'text' })
</pre>
The following code can be used to export parts of the database:
<syntaxhighlight pre lang="'xquery"'>
let $target := '/home/john/xml/target'
for $doc in db:get('DB', 'collection')
* {{Code|db:put("DB", document { <a/> }, "docs/dir/doc.xml")}} 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:
<syntaxhighlight pre lang="'xquery"'>
let $source := '/home/john/xml/source'
for $file in file:list($source, true())
* {{Code|db:put-binary('DB', file:read-binary('video.mov'), 'video/sample.mov')}} stores the addressed video file at the specified location.
* With the following query, you can copy the binary resources of one database into another:
<syntaxhighlight pre lang="'xquery"'>
let $db := 'db'
let $src-path := 'src/'
* {{Code|db:put-value('DB', 1 to 10000, 'sequence')}} stores a numeric range in the database.
* With the following query, a map with countries and associated cities is stored in a database. The value resource can e.g. be used as index in future queries:
<syntaxhighlight pre lang="'xquery"'>
db:put-value(
'factbook',
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu