Difference between revisions of "XQuery 3.0"

From BaseX Documentation
Jump to navigation Jump to search
Line 15: Line 15:
 
   1 + '2'
 
   1 + '2'
 
  } catch *($code, $desc) {
 
  } catch *($code, $desc) {
   concat('Error [', $code, ']: ', $desc)
+
   fn:concat('Error [', $code, ']: ', $desc)
 
  }</pre>  
 
  }</pre>  
'''Result:''' <code>Error [XPTY0004]: '+' operator: number expected, string found.</code>  
+
'''Result:''' <code>Error [XPTY0004]: '+' operator: number expected, string found.</code>
  
 
==Switch==
 
==Switch==

Revision as of 18:11, 12 January 2011

This article summarizes the most important features of the upcoming Version 3.0 of the XQuery language that have already been implemented in BaseX.

Group By

FLWOR expressions have been extended by the group by clause, which is well-established among relational database systems. Group by clauses can be used to group query results based on its values.

Michi? (Example, Details)...

Try/Catch

The try/catch construct can be used to handle errors at runtime:

Example:

 try {
   1 + '2'
 } catch *($code, $desc) {
   fn:concat('Error [', $code, ']: ', $desc)
 }

Result: Error [XPTY0004]: '+' operator: number expected, string found.

Switch

The switch statement is available in many other programming languages. It chooses one of several expressions to evaluate based on its input value.

Example:

for $fruit in ("Apple", "Pear", "Peach")
return switch ($fruit)
  case "Apple" return "red"
  case "Pear"  return "green"
  case "Peach" return "pink"
  default      return "unknown"

Result: red green pink

Serialization

Serialization parameters can now be defined within XQuery expressions. All available parameters are supported, which are specified in the W3C Serialization Document. Parameters are placed in the query prolog and need to be specified as option declarations, using the output prefix.

Example:

declare option output:omit-xml-declaration "no";
declare option output:method "xhtml";
<html/>

Result: <?xml version="1.0" encoding="UTF-8"?><html></html>

Functions

The following list includes all new XQuery 3.0 Functions that are already supported by BaseX:

...