Jon's Blog

Coder, Ex BBC. Cycling obsessive and writer for cyclosport.org

Useful XQuery

As I mentioned in my previous blog post I’ve recently been doing some work building RESTFul API’s backed by a Mark Logic XML Content Store utilising XQuery for document retrieval which has led me come up with the following useful snippets of XQuery that I thought I would share. They could easily be altered to work with slightly different requirements.

List all the document uris in database


List all the document uris in database based on some criteria


In this case we are restricting the documents that exist in the /sitemap/ directory and end with sitemap.xml and do not contain archive in the uri

Delete all the document in the database


Delete all the document in database based on some criteria


In this case we are deleting documents that are in the /content/ directory and whose uri ends with NEWSML.xml

Query a document by an element with a certain value


This could be easily altered to match on any element or attribute in your xml.

Actually a much more efficient way of doing the same is:

Slightly more advanced…

Retrieving document sizes


Very useful for getting a view of the size of your documents

This is how the results are returned

Adding a depth attribute to your xml documents


Why is this useful I hear you say, demonstrates how to use xdmp:node-replace and xdmp:node-insert-child

Comments