Changes

Jump to navigation Jump to search
68 bytes added ,  16:32, 27 February 2020
no edit summary
You can access multiple databases in a single query:
<pre classsyntaxhighlight lang="brush:xquery">
for $i in 1 to 100
return db:open('books' || $i)//book/title
</presyntaxhighlight>
If the {{Option|DEFAULTDB}} option is turned on, the path argument of the {{Code|fn:doc}} or {{Code|fn:collection}} function will first be resolved against the globally opened database.
The {{Code|fn:document-uri}} and {{Code|fn:base-uri}} functions return URIs that can also be reused as arguments for the {{Code|fn:doc}} and {{Code|fn:collection}} functions. As a result, the following example query always returns {{Code|true}}:
<pre classsyntaxhighlight lang="brush:xquery">
every $c in collection('anyDB')
satisfies doc-available(document-uri($c))
</presyntaxhighlight>
If the argument of {{Code|fn:doc}} or {{Code|fn:collection}} does not start with a valid database name, or if the addressed database does not exist, the string is interpreted as URI reference, and the documents found at this location will be returned. Examples:
If the API you use does not support binary output (this is e.g. the case for various [[Clients|Client]] language bindings), you need to convert your binary data to its string representation before returning it to the client:
<pre classsyntaxhighlight lang="brush:xquery">
string(db:retrieve('multimedia', 'sample.avi'))
</presyntaxhighlight>
==HTTP Services==
You may also use the BaseX-specific [[Database Module|XQuery Database Functions]] to create, add, replace, and delete XML documents:
<pre classsyntaxhighlight lang="brush:xquery">
let $root := "/path/to/xml/documents/"
for $file in file:list($root)
return db:add("database", $root || $file)
</presyntaxhighlight>
Last but not least, XML documents can also be added via the GUI and the ''Database'' menu.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu