Changes

Jump to navigation Jump to search
4,284 bytes added ,  15:33, 22 November 2017
no edit summary
=Conventions=
All functions and errors in this module are assigned to the {{Code|<code><nowiki>http://basex.org/modules/inspect}} </nowiki></code> namespace, which is statically bound to the {{Code|inspect}} prefix.<br/>All errors xqDoc document instances are assigned to the {{Code|<code><nowiki>http://basexwww.xqdoc.org/errors}} 1.0</nowiki></code> namespace, which is statically bound to the {{Code|bxerrxqdoc}} prefix.
=FunctionsReflection= ==inspect:functions== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|inspect:functions||function(*)*}}<br/>{{Func|inspect:functions|$uri as xs:string|function(*)*}}|-| '''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 will be 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 class="brush:xquery">declare %private function local:one() { 12 };declare %private function local:two() { 34 };for $f in inspect:functions() return $f()</pre>Compiles all functions in {{Code|code.xqm}} and invokes the function named {{Code|run}}:<pre class="brush:xquery">let $uri := 'code.xqm'let $name := "run"for $f in inspect:functions($uri)where local-name-from-QName(function-name($f)) = $namereturn $f()</pre>|} ==inspect:function-annotations== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|inspect:function-annotations|$function as function(*)?|map(xs:QName, xs:anyAtomicType*)}}<br/>|-| '''Summary'''|Returns the annotations of the specified {{Code|$function}} in a map.|-| '''Examples'''|* Returns an empty map:<pre class="brush:xquery">inspect:function-annotations(true#0)</pre>* 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 class="brush:xquery">declare %private function local:f() { 'well hidden' };inspect:function-annotations(local:f#0)</pre>|} ==inspect:static-context== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|inspect:static-context|$function as function(*)?, $name as xs:string|item()*}}<br/>|-| '''Summary'''|Returns a component of the [https://www.w3.org/TR/xquery-31/#dt-static-context static context] of a {{Code|$function}} with the specified {{Code|$name}}. If no function is supplied, the current static context is considered.<br/>The following components can be requested:* {{Code|base-uri}}: Static base URI.* {{Code|namespaces}}: Prefix/URI map with all statically known namespaces.* {{Code|element-namespace}}: Default element/type namespace URI, or an empty sequence if it is absent.* {{Code|function-namespace}}: Default function namespace URI, or an empty sequence if it is absent.* {{Code|collation}}: URI of the default collation.* {{Code|ordering}}: Ordering mode ({{Code|ordered}}/{{Code|unordered}})* {{Code|construction}}: Construction mode ({{Code|preserve}}/{{Code|strip}})* {{Code|default-order-empty}}: Default order for empty sequences ({{Code|greatest}}/{{Code|least}})* {{Code|boundary-space}}: Boundary-space policy ({{Code|preserve}}/{{Code|strip}})* {{Code|copy-namespaces}}: Copy-namespaces mode ({{Code|inherit}}/{{Code|no-inherit}}, {{Code|preserve}}/{{Code|no-preserve}})* {{Code|decimal-formats}}: Nested map with all statically known decimal formats|-| '''Examples'''|* Returns the static base URI (same as {{Code|static-base-uri()}}):<pre class="brush:xquery">inspect:static-context((), 'base-uri')</pre>* Returns a map with all namespaces that are statically known in the module of the specified function:<pre class="brush:xquery">import module namespace data = 'data.xqm';inspect:static-context(data:get#1, 'namespaces')</pre>|-| '''Errors'''|{{Error|unknown|#Errors}} The specified component does not exist.|} =Documentation=
==inspect:function==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|inspect:function|$function as function(*)|element(function)}}
|-
| '''Summary'''
|Inspects the specified {{Code|$function}} and returns an element that describs describes its structure. The output of this function is similar to eXist-db’s [http://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 class="brush:xml">
<function name="count" uri="http://www.w3.org/2005/xpath-functions" external="false">
<argument type="item()" occurrence="*"/>
<return type="xs:integer"/>
…is represented by {{Code|inspect:function(local:same#1)}} as…
<pre class="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"/>
==inspect:context==
 
{| width='100%'
|-
|-
| '''Summary'''
|Generates an element that describes all variables and functions in the current query context.
|-
|'''Examples'''|An example is [[#Examples|shown below]]Evaluate all user-defined functions with zero arguments in the query context:<br/><pre class="brush:xquery">inspect:context()/function ! function-lookup(QName(@uri, @name), 0) ! .()</pre>Return the names of all private functions in the current context:<pre class="brush:xquery">for $f in inspect:context()/functionwhere $f/annotation/@name = 'private'return $f/@name/string()</pre>
|}
==inspect:context-functionsmodule=={| width='100%'|-| width='120' | '''Signatures'''|{{Func|inspect:context-functions||function(*)*}}|-| '''Summary'''|Returns all user-defined functions that are known in the current query context.|-|'''Examples'''|An example is [[#Examples|shown below]].|}
==inspect:module==
{| width='100%'
|-
|-
| '''Summary'''
|Retrieves the string from resource located at the specified {{Code|$inputuri}}, parses it as XQuery module, and generates an element that dscribes its describes the module's structure.|-| '''Errors'''|{{Error|FODC0002|XQuery Errors#Functions Errors}} A relative URI will be resolved against the static base URI of the addressed resource cannot be retrievedquery.
|-
|'''Examples'''
==inspect:xqdoc==
 
{| width='100%'
|-
|-
| '''Summary'''
|Retrieves the string from resource located at the specified {{Code|$inputuri}}, 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 a 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: [http://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'''
<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"/>
</xqdoc:xqdoc>
</pre>
 
=Errors=
 
{| class="wikitable" width="100%"
! width="110"|Code
|Description
|-
|{{Code|unknown}}
|The specified component does not exist.
|}
=Changelog=
 
;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.
 
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu