Working with JSON in XQuery

Author: Dave Cassel  |  Category: Software Development

MarkLogic supports two native languages, XQuery and JavaScript. XQuery is a very natural way to work with XML, just as JavaScript is a very natural way to work with JSON. However, sometimes it’s useful to cross over and work with JSON using XQuery or vice versa. This post has some tips on using XQuery to […]

Memoization in XQuery

Author: Dave Cassel  |  Category: Software Development

Memoization is tracking partial solutions so that they don’t have to be recalculated. A good example of where this is handy is the Fibonacci sequence. You may remember that the definition of this is: F(n) = F(n -1) + F(n – 2) F(1) = 1 F(2) = 1 Clearly, this is a recursive function. Let’s take a […]

Fixing a slow XQuery function

Author: Dave Cassel  |  Category: Software Development

Sometimes an application is slower to respond than we like. There are a variety of reasons this can happen — hardware, indexes, algorithms. MarkLogic offers some tools to investigate the software aspects of code running too slow. The rest of this post is a case study investigating slow responses on a project I worked on […]

XQuery: finding values in one sequence that aren’t in another

Author: Dave Cassel  |  Category: Software Development

During a recent working session, a question came up about how to quickly find all the values in one sequence that aren’t in another. A little poking around the web turns up what seems to be the standard approach: I found that approach in a couple places, including functx’s implementation. If I’m thinking about it right, […]

Recursive Descent in XQuery

Author: Dave Cassel  |  Category: Software Development

This post covers a technique that’s an oldie but a goodie, with some thoughts on how it applies with today’s MarkLogic features. I reviewed this with my team recently and we thought it would make a good reference. The post will cover both some available implementations and the raw technique itself, and when to use […]

A trick with cts:near-query

Author: Dave Cassel  |  Category: Software Development

A reader recently emailed me a question about an old post on the MarkLogic developer’s mailing list. The goal was to run a query such that an element’s value and an attribute on that element both matched. The problem was that the queries the asker built would match one element’s value and a different element’s […]

Converting CSV to XML

Author: Dave Cassel  |  Category: Software Development

I just published an XQuery library to GitHub to convert lines of Comma Separated Value data to XML. That can probably be done more simply if you don’t care what the XML looks like, but I wanted to build templates so that I could get good structure. I also built in an action mechanism, so that […]

Priority Task Spawning in MarkLogic 5

Author: Dave Cassel  |  Category: Software Development

MarkLogic has long had the ability to spawn tasks, consisting of a module, a set of variables and some options. Those tasks go into the task queue and get worked off by the configured number of threads. A new feature in MarkLogic 5 gives a new option: higher priority tasks. Let’s take a look at […]

Range Indexes and Empty Elements

Author: Dave Cassel  |  Category: Software Development

I’ve started a couple posts lately, only to find them more complex than expected. So to get myself back on the board, tonight you get a pretty simple one, based on an error one of my colleagues encountered recently. Suppose we have an int range element index set up on <count/> in our MarkLogic database. xdmp:document-insert( […]

Sneak Peak: ImageMagick in MarkLogic

Author: Dave Cassel  |  Category: Software Development

Today I get to give you a sneak peak into a feature that’s not yet officially present, but you’ll find if you know where to look: XQuery-level integration with ImageMagick! In this post I demonstrate automatically scaling down large images for CurioVault.com.