XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.

advertisement

Scaling Up with XQuery, Part 1
by Bob DuCharme | Pages: 1, 2, 3

MarkLogic Server

MarkLogic is carving out an expanding niche as a professional high-end XQuery engine. They make a free version of the product available as a marketing tool, and unlike the free software offered by other companies on a "try before you buy" basis, the limitations imposed on the use of the free MarkLogic server will still let you get some serious work done. If you need professional services, want to deploy an app beyond one or two desktops, want to take advantage of features such as automatic batch conversion of various non-XML formats to XML for loading into their server, or want to scale up your XML database to a really large size, they'd be happy to sell you licenses.

There are various approaches to using the MarkLogic server, but the classic one is to install it as a web server and run HTTP requests against it. After downloading and installing the MarkLogic server, pick Admin MarkLogic Server from the MarkLogic Server section of your Windows Start menu. The first screen asks for a license key and provides a link to get one for an evaluation copy of the software. For an evaluation license, you have two choices:

  • The Community License, which stores up to 100 megabytes and can be used for an unlimited time on personal projects. A given company can only use two copies.

  • The Trial license lets you store up to a gigabyte of data, but only works for 30 days.

After you get the license key, the server restarts, asks you a few questions (including a username and password that you'll need to access the administration screen and the data in your applications), and takes you to the Server's System Summary page. In the default server configuration, http://127.0.0.1:8001/ is the URL for the admin page. http://localhost:8000/use-cases/ takes you to a use cases page with frames that let you enter and view the results of XQuery queries. This includes links to sample queries, but you can enter any query you like in the "XQuery Source" frame, including queries against the RecipeML recipes once they're loaded.

Before creating a MarkLogic application, you must create an application server. On the tree at the left of the administration screen, pick Groups, Default, App Servers, and then select the Create HTTP tab that appears. It needs a port number to use for your new application server and a directory where that server's data will be stored; I assigned a port number of 8009 and created a myserverroot subdirectory of the default \Program Files\MarkLogic production installation directory for the data.

At this point, it's a good idea to put a small, simple HTML file named default.xqy in that directory and to then send a browser to http://localhost:8009. You should see your HTML file in the browser. Just as index.html is the default filename to retrieve from a directory stored on an Apache web server and default.asp is used for a Microsoft IIS server, default.xqy is the default filename for the MarkLogic server. As you'll see, you can store complex XQuery queries in these files, but simple HTML works as well.

I had my recipe files in a directory named c:\dat\xquery\recipeml, so I created the following script to load them into the MarkLogic server.


(: Load recipe files into MarkLogic database. :)

<html xmlns="http://www.w3.org/1999/xhtml"><body>
{ 

  (: Instead of 3 file names, the actual loadrecipes.xqy script has 291. :)
  let $filenames := ("_Baking_the_Best_Muffins_","_Butter_","_Brown_Bag__French_Apple_Pie") 

  for $dataFilename in $filenames
    return (xdmp:document-load(concat("c:/dat/xquery/recipeml/",$dataFilename,".xml"),
    <options xmlns="xdmp:document-load" xmlns:http="xdmp:http">
      <repair>none</repair>
      <permissions>{xdmp:default-permissions()}</permissions>
      <format>xml</format>
    </options>),
    xdmp:document-add-collections(concat("c:/dat/xquery/recipeml/",$dataFilename,".xml"),
                                  "recipes"))
}
<p>OK</p>
</body></html>

After creating a subdirectory of my new myserverroot directory named recipes, I put this script in a file named loadrecipes.xqy in that directory and sent my browser to http://localhost:8009/recipes/loadrecipes.xqy to run it. As with many XQuery queries (and ASP files), this one takes the form of an HTML file with delimited sections to generate the necessary data. In this case, the only generated HTML outside of the basic skeleton is a paragraph that says "OK" when all the files are loaded, but if there are problems loading the documents into the MarkLogic Server database, the error messages will also appear in your browser.

Pages: 1, 2, 3

Next Pagearrow