Solutions

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Learn

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Community

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Company

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

 
Knowledgebase:
XQuery and JavaScript interoperability
08 February 2015 04:57 PM

Introduction

This article discusses the use of XQuery in JavaScript and vice versa.

Using XQuery in JavaScript

A JavaScript module in MarkLogic can also import an XQuery library and access its functions and variables as if they were JavaScript. If you’re working primarily in JavaScript, but you have an existing library in XQuery or a specialized task that would be better suited to XQuery, you can write just that library in XQuery and import it into a JavaScript module.

The calling JavaScript module doesn’t need to even know that the library was implemented in XQuery. MarkLogic automatically makes all of the public functions and variables of the XQuery library available as native JavaScript functions and variables in the calling JavaScript module.  (This is what’s happening when you import one of MarkLogic’s many libraries that come bundled with the server, such as Admin or Security.)

This capability will be key for those developers with existing investments in XQuery that want to start using JavaScript without having to rewrite all of their libraries.

Using JavaScript in XQuery

You can't import JavaScript libraries to XQuery, but you can call xdmp:invoke with a JavaScript main module or evaluate a string of JavaScript with xdmp:javascript-eval.

(7 vote(s))
Helpful
Not helpful

Comments (0)