Changes

Jump to navigation Jump to search
|-
| '''Summary'''
|Returns function items for all user-defined functions (both public and private) that are known in the current query context. If a {{Code|$uri}} is specified, the addressed module specified resource will be retrieved as string and compiled, and its functions will be added to the query context and returned to the user. A relative URI will be resolved against the static base URI of the query.
|-
|'''Examples'''
|Invokes the declared functions and returns their values:<br/>
<pre classsyntaxhighlight lang="brush:xquery">
declare %private function local:one() { 12 };
declare %private function local:two() { 34 };
for $f in inspect:functions() return $f()
</presyntaxhighlight>
Compiles all functions in {{Code|code.xqm}} and invokes the function named {{Code|run}}:
<pre classsyntaxhighlight lang="brush:xquery">
let $uri := 'code.xqm'
let $name := "'run"'
for $f in inspect:functions($uri)
where local-name-from-QName(function-name($f)) = $name
return $f()
</presyntaxhighlight>
|}
==inspect:function-annotations==
 
{{Mark|Introduced with Version 8.5}}
{| width='100%'
|
* Returns an empty map:
<pre classsyntaxhighlight lang="brush:xquery">
inspect:function-annotations(true#0)
</presyntaxhighlight>
* Returns a map with a single key <code><nowiki>Q{http://www.w3.org/2012/xquery}private</nowiki></code> and an empty sequence as value:
<pre classsyntaxhighlight lang="brush:xquery">
declare %private function local:f() { 'well hidden' };
inspect:function-annotations(local:f#0)
</presyntaxhighlight>
|}
==inspect:static-context==
 
{{Mark|Introduced with Version 8.5}}
{| width='100%'
|
* Returns the static base URI (same as {{Code|static-base-uri()}}):
<pre classsyntaxhighlight lang="brush:xquery">
inspect:static-context((), 'base-uri')
</presyntaxhighlight>
* Returns a map with all namespaces that are statically known in the module of the specified function:
<pre classsyntaxhighlight lang="brush:xquery">
import module namespace data = 'data.xqm';
inspect:static-context(data:get#1, 'namespaces')
</presyntaxhighlight>
|-
| '''Errors'''
=Documentation=
 
==inspect:type==
 
{{Mark|Updated with Version 9.6:}} options added.
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|inspect:type|$value as item()*|xs:string}}<br/>{{Func|inspect:type|$value as item()*, $options as map(*)|xs:string}}
|-
| '''Summary'''
|Returns a string representation of the type of a {{Code|$value}}:
* The string includes the occurrence indicator.
* The type of functions and nodes may be stricter than the returned type.
* For type checking, the standard expressions {{Code|typeswitch}} and {{Code|instance of}} should be used instead.
The following {{Code|$options}} are available:
* {{Code|item}}: If enabled, only the item type is returned and the occurrence indicator is omitted. The default is {{Code|false()}}.
* {{Code|mode}}: If {{Code|value}} is specified, the assigned type of the result value is returned. With {{Code|expression}} the type of the input expression is returned (please note that the original expression may already have been rewritten at compile-time). With {{Code|computed}}, the exact value is computed at runtime, based on the expression and the result value. The default is {{Code|computed}}.
|-
| '''Examples'''
|
* <code>inspect:type((<a/>, <a/>))</code> yields <code>element(a)+</code>
* <code>inspect:type(map { 'a': (1, 2)[. = 1] })</code> yields <code>map(xs:string, xs:integer)</code>
* <code>inspect:type(1 to 100, map { 'item': true() })</code> yields <code>xs:integer</code>
|}
==inspect:function==
 
{| width='100%'
|-
|-
| '''Summary'''
|Inspects the specified {{Code|$function}} and returns an element that describes its structure. The output of this function is similar to eXist-db’s [httphttps://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/inspection&location=java:org.exist.xquery.functions.inspect.InspectionModule inspect:inspect-function] function.
|-
|'''Examples'''
|The query {{Code|inspect:function(count#1)}} yields:
<pre classsyntaxhighlight lang="brush:xml"><function name="count" uri="http://www.w3.org/2005/xpath-functions" external="false">
<argument type="item()" occurrence="*"/>
<return type="xs:integer"/>
</function>
</presyntaxhighlight>
The function…
<pre classsyntaxhighlight lang="brush:xquery">
(:~
: This function simply returns the specified integer.
$number
};
</presyntaxhighlight>
…is represented by {{Code|inspect:function(local:same#1)}} as…
<pre classsyntaxhighlight lang="brush:xml"><function name="local:same" uri="http://www.w3.org/2005/xquery-local-functions" external="false">
<argument type="xs:integer" name="number">number to return</argument>
<annotation name="private" uri="http://www.w3.org/2012/xquery"/>
<return type="xs:integer">specified number</return>
</function>
</presyntaxhighlight>
|}
==inspect:context==
 
{| width='100%'
|-
| '''Examples'''
|Evaluate all user-defined functions with zero arguments in the query context:<br/>
<pre classsyntaxhighlight lang="brush:xquery">
inspect:context()/function ! function-lookup(QName(@uri, @name), 0) ! .()
</presyntaxhighlight>
Return the names of all private functions in the current context:
<pre classsyntaxhighlight lang="brush:xquery">
for $f in inspect:context()/function
where $f/annotation/@name = 'private'
return $f/@name/string()
</presyntaxhighlight>
|}
==inspect:module==
 
{| width='100%'
|-
|-
| '''Summary'''
|Retrieves the resource located at the specified {{Code|$uri}}, parses it as XQuery module, and generates an element that describes the module's structure.|-| '''Errors'''|{{Error|FODC0002|XQuery Errors#Functions Errors}} A relative URI will be resolved against the addressed resource cannot be retrievedstatic base URI of the query.
|-
|'''Examples'''
==inspect:xqdoc==
 
{| width='100%'
|-
|-
| '''Summary'''
|Retrieves the resource located at the specified {{Code|$uri}}, parses it as XQuery module, and generates an xqDoc element. A relative URI will be resolved against the static base URI of the query.<br/>[http://xqdoc.org / xqDoc] provides a simple vendor-neutral solution for generating documentation from XQuery modules. The documentation conventions have been inspired by the JavaDoc standard. Documentation comments begin with {{Code|(:~}} and end with {{Code|:)}}, and tags start with {{Code|@}}. xqDoc comments can be specified for main and library modules and variable and function declarations.<br/>We have slightly extended the xqDoc conventions to do justice to the current status more recent versions of XQuery (Schema: [httphttps://files.basex.org/etc/xqdoc-1.1.30052013.xsd xqdoc-1.1.30052013.xsd]):<br/>
* an {{Code|<xqdoc:annotations/>}} node is added to each variable or function that uses annotations. The xqdoc:annotation child nodes may have additional {{Code|xqdoc:literal}} elements with {{Code|type}} attributes (xs:string, xs:integer, xs:decimal, xs:double) and values.
* a single {{Code|<xqdoc:namespaces/>}} node is added to the root element, which summarizes all prefixes and namespace URIs used or declared in the module.
* name and type elements are added to variables.
|-
| '''Errors'''
|{{Error|FODC0002|XQuery Errors#Functions Errors}} the addressed resource cannot be retrieved.
|-
|'''Examples'''
This is the {{Code|sample.xqm}} library module:
<pre classsyntaxhighlight lang="brush:xquery">
(:~
: This module provides some sample functions to demonstrate
$number
};
</presyntaxhighlight>
If {{Code|inspect:module('sample.xqm')}} is run, the following output will be generated:
<pre classsyntaxhighlight lang="brush:xml">
<module prefix="samples" uri="http://basex.org/modules/samples">
<description>This module provides some sample functions to demonstrate
<see>http://docs.basex.org/wiki/XQDoc_Module</see>
<version>1.0</version>
<variable name="samples:test-string" uri="http://basex.org/modules/samples" type="xs:string" external="false">
<description>This is a sample string.</description>
</variable>
<function name="samples:same" uri="http://basex.org/modules/samples" external="false">
<argument name="number" type="xs:integer">number to return</argument>
<annotation name="private" uri="http://www.w3.org/2012/xquery"/>
</function>
</module>
</presyntaxhighlight>
The output looks as follows if {{Code|inspect:xqdoc('sample.xqm')}} is called:
<pre classsyntaxhighlight lang="brush:xml">
<xqdoc:xqdoc xmlns:xqdoc="http://www.xqdoc.org/1.0">
<xqdoc:control>
</xqdoc:functions>
</xqdoc:xqdoc>
</presyntaxhighlight>
=Errors=
=Changelog=
 
;Version 9.6
* Updated: [[#inspect:type|inspect:type]]: options added
 
;Version 9.3
* Added: [[#inspect:type|inspect:type]]
;Version 8.5
 
* Added: [[#inspect:function-annotations|inspect:function-annotations]], [[#inspect:static-context|inspect:static-context]]
* Updated: {{Code|external}} attribute added to variables and functions
* Updated: Relative URIs will always be resolved against the static base URI of the query
;Version 7.9
 
* Updated: a query URI can now be specified with [[#inspect:functions|inspect:functions]].
This module was introduced with Version 7.7.
Bureaucrats, editor, reviewer, Administrators
12,413

edits

Navigation menu