Documentation

In a Nutshell

XQuery in the Browser relies on four basic principles:

  1. A Web page can contain one or several library modules or main modules written in script tags having the type application/xquery.
  2. The main modules on a Web page are executed in the order in which they appear.
  3. The (XDM) output by each main module is inserted onto the HTML page after the corresponding script tag.
  4. A main module (or, recursively, a library module) can import, in addition to built-in modules, any library module declared earlier on the page.

Launching the MXQuery engine

For the XQuery code to be executed at all, you need to launch the MXQuery engine by putting the following script tag with a link to the MXQuery JavaScript code (you need to download the corresponding files and put them on the same server, or locally if you are using XQIB locally - not all browsers will support local XQIB execution though):

<script type="text/javascript"
        src="path/to/mxqueryjs/mxqueryjs.nocache.js"></script>
			

XQuery specifications

XQIB implements the following recommendations:

  • XQuery 1.0
  • XQuery Update Facility 1.0

as well as the following working drafts (partially, or not necessarily up-to-date)

  • XQuery 3.0
  • XQuery Scripting Extension 1.0
  • XQuery Full Text

Browser API

For your convenience, XQIB provides you with a set of functions. These functions are in a special namespace which is bound by default to the prefix “b”. Functions marked as side-effecting correspond to sequential functions as defined in the XQuery Scripting Extension. This means that any function using them must itself be declared as sequential as well.

DOM Access

XQuery natively supports tree navigation. The HTML5 DOM is made available as a document node through the b:dom() function defined below. It is then possible to navigate in the document using XPath expressions (a subset of XQuery). For example, all input tags with an attribute name of value “mybutton” can be retrieved with:

b:dom()//input[@name="mybutton"]
			

			  b:dom() as document()
			

Returns the document node of the current HTML page.

CSS Access

b:getStyle($what as element(),
           $kind as xs:string) as xs:string
			

Returns the CSS style $kind associated with the element $what.

b:setStyle($what as element(),
           $kind as xs:string,
           $newvalue as xs:string) as empty-sequence()
			

Sets the CSS style $kind associated with the element $what to $newvalue. – side-effecting

Event Listener Management

b:addEventListener($where as element(),
                   $kind as xs:string,
                   $listener as function(node(), node()) as empty-sequence()
			

Binds an event of kind $kind to the node $where. When such an event is raised, $listener (a function) is called. $listener must take two parameters: the HTML node where the event occurs (it will be $where) as well as an XML node containing information about the event. – side-effecting

b:removeEventListener($where as element(),
                      $kind as xs:string,
                      $listener as function(node(), node()) as empty-sequence()
			

Unbinds an event of kind $kind to the node $where. When such an event is raised, $listener is no longer called. - side-effecting

Helper functions

b:alert($message as xs:string) as empty-sequence()
			

Displays the pop-up message passed in $message. – side-effecting

REST Functions

XQIB provides an implementation of the EXPath http-client module so that you can make REST calls (GET, POST…) with http-client:send-request (side-effecting). The http-client namespace is not bound to any prefix by default, so you will need to import this module explicitly.

Once you have made an HTTP request and received an XML document, you can navigate through it just the same way you navigate through the HTML page: using XPath expressions.