Monthly Archives: September 2015

Analysing XML with BaseX

TEI XML, often used for encoding texts in the humanities, actually carries in its elements certain semantic load. This means that just knowing which elements are used for encoding a file could provide some basic information about the file and its salient points.

We decided to experiment with two XQuery functions. One, currently called croala-analist, lists all documents in a database, e. g. for the database latty: latty. At the same time, as an orientational help, the function lists number of distinct elements used for encoding; e. g. there are eight different elements in the text part of the document putsch-c-brevis.xml.

The other function provides information on distinct elements: in XML/XPath parlance, who are their parents and their children, and how many occurrences of a certain element there are in the document. Here is the information for a latty document mentioned above: putsch-c-brevis.xml.

Joe Futrelle, "Guernica" (from Flickr)
Joe Futrelle, “Guernica” (from Flickr)

An additional challenge for our coding skills was making these functions as general as possible, i. e. applicable to all databases on our server. The two functions can be found inside the croala.xqm module in our Bitbucket repository (croalatransform / plutonbasex / repo /); functions are croala:analist and croala:anatomia.