Jump to navigation Jump to search
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
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))
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'))
==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)
Last but not least, XML documents can also be added via the GUI and the ''Database'' menu.
Bureaucrats, editor, reviewer, Administrators


Navigation menu