XQuery on eXist – OSX

eXist db is an open-source database application that I have been using for the past few weeks as part of my ‘Data Integration’ course by Professor Jan Chomicki.

On the Mac OSX, installation is quite straightforward. Download the .jar file available for the latest stable release and double click on the downloaded file. Follow the instructions to complete installation.

Move the eXist db application to the Applications Folder

Move the eXist db application to the Applications Folder

Once installation is complete, you can double click on the installed application to start the eXist db on your machine. The first time it opens, it will upload and install the apps that were selected during installation.

eXist db uploads the applications selected by the installer

eXist db uploads the applications selected by the installer

Once started, it can be accessed on the Menu Bar at the top of the screen. The dashboard of the eXist db application can be accessed at http://localhost:8080 and it will look like the image below. As you can see, it indeed does come packed with quite a few options.

eXist db dashboard

eXist db dashboard

Documentation

The dashboard has access to quite significant documentation at http://localhost:8080/exist/apps/doc/ and is available offline too! This should be a one stop shop for all troubleshooting w.r.t the application.

I am going to illustrate how to run some simple XQuery queries on an XML document and generate output for the same.

Adding Collections/Documents

This can either be done via the Admin Web Application or the Collections Browser options on the dashboard. It provides a simple file-navigation type interface where you can create collections, add to collections and remove from the collection. The default username for login is ‘admin’ and password is empty.

Too add a file, choose a file using the “Browse” option. Then select a name to store it in the collection as and click on “Upload”. The file is uploaded to the current open collection. You can see the document uploaded in the collection. I have uploaded two documents “ADB.xml” and “BDB.xml” as you see from the below screenshot.

Upload document to eXist db collection

Upload document to eXist db collection

Running XQuery

Click on the eXide – XQuery IDE in the dashboard. You can click on New XQuery to create a new document. Type in your query there and click on Run to see the XML Output in the results panel. You can also enable “Live Preview” to see the results instantly (as you type). If there are issues in your query, the IDE gives you errors/warnings.

The following are some simple queries to inspect the XML and fetch data from it.

eXist db eXide IDE Sample XQuery

eXist db eXide IDE Sample XQuery

eXist db eXide IDE Sample XQuery

XQuery is much more powerful and quite a lot can be done using it. From Wikipedia:

XQuery is a query and functional programming language that is designed to query and transform collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, binary, etc.)

W3C Specifications contain a lot of information about FLWOR(For, Let, Where, Order by, Return) Expressions using XQuery – http://www.w3.org/TR/xquery/#id-flwor-expressions

Leave a Reply

Your email address will not be published. Required fields are marked *