Changes

Jump to navigation Jump to search
84 bytes removed ,  18:30, 1 December 2023
m
Text replacement - "<syntaxhighlight lang="xquery">" to "<pre lang='xquery'>"
You can access multiple databases in a single query:
<syntaxhighlight pre lang="'xquery"'>
for $i in 1 to 100
return db:get('books' || $i)//book/title
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}}:
<syntaxhighlight pre lang="'xquery"'>
every $c in collection('anyDB')
satisfies doc-available(document-uri($c))
If the API you use does not support binary output (which is e.g. the case for various [[Clients|Client]] language bindings), you can convert your binary data to its string representation before returning it to the client:
<syntaxhighlight pre lang="'xquery"'>
string(db:get-binary('multimedia', 'sample.avi'))
</syntaxhighlight>
With {{Function|Database|db:get-value}}, XQuery values can be retrieved. In the following example, we assume that an XQuery map {{Code|cities}} was stored in an {{Code|indexes}} database:
<syntaxhighlight pre lang="'xquery"'>
let $city-map := db:get-value('indexes', 'cities')
return $city-map?Chile
You can also use functions from the [[Database Module]] to add, replace, or delete XML documents:
<syntaxhighlight pre lang="'xquery"'>
db:add('documents', '/path/to/xml/resources/')
</syntaxhighlight>
Function from other modules, such as the [[File Module]], can be utilized to filter the input. With the following code, all files that contain numbers in the filename are selected, and stored as XML. If an input file contains no well-formed XML, it is stored as binary resource, and the error message is stored as a string value:
<syntaxhighlight pre lang="'xquery"'>
let $db := 'documents'
let $root := '/path/to/resources/'
The error messages can e.g. be analyzed in a second step:
<syntaxhighlight pre lang="'xquery"'>
let $errors := db:get-value('documents')
for $filename in map:keys($errors)
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu