Joy (and pain) but Mostly Joy

Volume 11, Issue 46; 13 May 2008; last modified 08 Oct 2010

On application servers and generating XML with XQuery.

I've always been pretty old school when it comes to web content. I've never gone in for the whole application server/development platform approach. Granted, I've never had to solve the sorts of production problems of scalability and dynamic content generation that they're designed to address.

To be honest, I've been put off mostly by two things: first, generating the content typically seems to involve some weird hybrid of markup and procedural programming language code using something like PHP or JSP. Clearly it can be made to work, it just doesn't feel right. And second, application servers seem to erect an awful lot of infrastructure between me and my data (and pushing my data into relational tables along the way does nothing to help).

With that in mind, I came to my new job believing that the Mark Logic Server was different and knowing that I was going to learn to like it. Or else.

I needed a little ramp-up, learning project so I started building a music management application. All of the music in our house stored on a server. I connect to that server with DAAP and listen to it in my office through my laptop, but the longer-range plan is to have it available more ubiquitously in the house. That means we'll eventually need some sort of a front-end for browsing and searching, building playlists, and performing other operations.

The data is a few megabytes of XML. There's nothing remarkable about it:

<album xml:base='/share/Music/flac/The_Who/The_Ultimate_Collection/disc1/' cover='1'>
  <artist>The Who</artist>
  <title>The Ultimate Collection Disc One</title>
  <track trackno='01' fileref='01-i_cant_explain' time='2:05:88'>
    <title>I Can't Explain</title>
  <track trackno='02' fileref='02-anyway_anyhow_anywhere' time='2:41:49'>
    <title>Anyway Anyhow Anywhere</title>

A few megabytes is by no means large, but it's big enough to make parsing it over and over again (think CGI) a little painful. I could break it down into relational tables, instead, but that's a different sort of pain. Popping it into Mark Logic Server, on the other hand, is completely straightfoward.

And now that I've got it in the server, I have nearly instantaneous access via XQuery, a language designed for querying and generating XML.

There's no question that XQuery has some, uh, idiosyncrasies, that are a little painful, but I was really surprised with how straightforward it was. The bulk of the application (neglecting some of the browser drag-and-drop stuff that I'll eventually need) is 160ish lines of XQuery. And not particularly proficient XQuery either, I expect.

You might ask how the hybrid of XML and XQuery differs from the hybrid of XML and Java. I think mostly it has to do with the fact that XQuery's natural idioms are XML-centric. I dunno, it just feels right. And Mark Logic Server feels like infrastructure in service to my data instead of being in the way.

Anyway, there's probably a limit to how much fanboyism I can get away with. Call me a shill if you must, but I'm really that impressed.


I had a very similar experience -- I felt a need to get my hands dirty with MarkLogic, and so found a defined, simple XML problem to solve (in my case, a dashboard view of content in Safari Books Online using the API).

Less than 50 lines later, I had a pretty robust web app that's still running almost unchanged more than a year later. I was also definitely really that impressed. I'm still not quite sure why XQuery hasn't caught on more for web apps (especially those that consume XML and display as HTML).

—Posted by Andrew Savikas on 15 May 2008 @ 03:03 UTC #