Element constructors: computed and direct

Author: Dave Cassel  |  Category: Software Development

In XQuery, you can build an element one of two ways: computed or direct. Direct This is the simpler case, so I’ll take it first. Direct means that your XQuery code has the XML you want to build: declare namespace blog = “http://davidcassel.net/blog”; <blog:example simple=”true”>   <blog:pointless/> </blog:example> XML is a natural data structure for […]

An XQuery Sequence question

Author: Dave Cassel  |  Category: Software Development

A while ago I was posed a question by a colleague: (1,3,2)[.] -> 1 (1,2,3)[.] -> 1 2 3 (2,3,4)[.] -> no result why? To find the answer, we need to think about what’s happening in the brackets. As discussed in one of my earlier posts, the expression in brackets gets evaluated once for each […]

Meaningful XML

Author: Dave Cassel  |  Category: Software Development

Another day, another code review. Today I came across a function that generates non-meaningful XML. This is something that at first glance feels like it has a nice structure to it, but there’s a better way. First, let take a look at the XML (I’ve changed the XML and the code to make it anonymous, […]

Exceptional code

Author: Dave Cassel  |  Category: Software Development

Today I was looking into some code that was running slower than it should, and I happened across this little tidbit: let $normal :=   try {     xs:int($value)   }   catch($e) {     $value   } Yes, MarkLogic extends XQuery to add try/catch, and this is a tremendously useful feature, when […]

TDD with XQuery

Author: Dave Cassel  |  Category: Software Development

Today I had a complicated function to write. The framework we’re using for this project has unit testing built into it, so for the first time in a long time, I did the Test Driven Development approach: I wrote a set of tests, then wrote code to pass the tests, and then refactored. It felt […]

Word query specification

Author: Dave Cassel  |  Category: Software Development

While looking at the database configuration in MarkLogic Server, have you ever noticed the Word Query link on the left? (Click Configure -> Databases -> the name of one of your databases -> Word Query.) Ever wonder what it does? Word Query is a simple way to specify what parts of a document should be […]

Unparsing a custom facet

Author: Dave Cassel  |  Category: Software Development

In many search applications, when we show the results of a user’s search, we also want to display the search that was done by putting the query string into a text box, especially if the search is built up from an advanced search screen. In some cases, we might want to modify the search before […]

A custom facet for the Search API

Author: Dave Cassel  |  Category: Software Development

I recently got to teach the MarkLogic Essentials class for MarkLogic University. To illustrate custom facets, I implemented one on the fly with the class watching. No pressure. :) The good news is that it (almost) worked with the first try — there was just one little problem with the display. This post shows the […]

text(), fn:string() and fn:data()

Author: Dave Cassel  |  Category: Software Development

I’m going to be teaching the MarkLogic University Basic XQuery class tomorrow, and as usually happens when I get to teach, I’ve learned something while reviewing the material. In this case, it’s the differences among text(), fn:string() and fn:data(). text() This one is commonly seen at the end of an XPath expression. It returns a […]

Expires headers in MarkLogic Server

Author: Dave Cassel  |  Category: Software Development

A little while ago I ran YSlow, a Firefox plugin that evaluates how quickly a web page loads, against an Application Builder based app I’d written. YSlow gave my site a grade C, with an overall performance score of 71 (out of 100). Some of the suggestions that YSlow offered are not simple to implement […]