In BaseX, two internal representations exist for XML nodes:
* 1. Database nodes are:** stored in a persistent database on disk;** nodes of a document that has been generated temporarily with {{Code|fn:doc}}, {{Code|fn:parse-xml}} and other functions; or** the result of a [[XQuery Update#Main-Memory Updates|main-memory update]].* 2. Fragments are similar to DOM structures. They are created when XQuery node constructors are used (<code><a/></code>, <code>element a { }</code>, etc.).
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 { }
</syntaxhighlightpre>
==Updating Functions==
|- valign="top"
| '''Summary'''
|Exports the specified {{Code|$database}} to the specified file {{Code|$path}}. Existing files will be overwritten.<br/>The {{Code|$options}} argument contains [[Serialization|serialization parameters]] (see [https://www.w3.org/TR/xpath-functions-31/#func-serialize fn:serialize()]).
|- valign="top"
| '''Errors'''
| '''Examples'''
| Export all files as text:<br/>
<syntaxhighlight pre lang="'xquery"'>
db:export("DB", "/home/john/xml/texts", map { 'method': 'text' })
</syntaxhighlightpre>
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')
file:write($path, $doc)
)
</syntaxhighlightpre>
|}
* {{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())
where not(file:is-dir($path))
return db:put('db', doc($path), $file)
</syntaxhighlightpre>
|}
* {{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/'
let $trg := $trg-path || substring-after($src, $src-path)
return db:put-binary($db, db:get-binary($db, $src), $trg)
</syntaxhighlightpre>
|}
* {{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',
),
'cities'
)</syntaxhighlightpre>
|}
|
* {{Code|db:rename("DB", "docs/dir/doc.xml", "docs/dir/newdoc.xml")}} renames the resource {{Code|docs/dir/doc.xml}} to {{Code|docs/dir/newdoc.xml}} in the database {{Code|DB}}.
* {{Code|db:rename("DB", "docs/dir", "docs/newdir")}} moves all resources in the database {{Code|DB}} from {{Code|docs/dir}} to {{Code|docs/newdir}}.
|}
{| class="wikitable" width="100%"
! width="110"|Code
|Description
|- valign="top"
|{{Code|args}}