4.2. Why Mechapoint uses XML

The main reason that Mechapoint uses an XML-based file format is it's ease of implementation. Obviously some kind of text-based file format was in order, given that the files are meant to be human generated, but parsing text is not an easy job, especially in a language such as C++. Because I'd already worked with XML, I immediately thought of it as the solution to my problem. Through the use of an XML parser, in this case GNOME's libxml2, the XML file is processed for you, and all your program sees is a tree of nodes which are easy to iterate and recurse through. It also has the advantage of making the files themselves fairly readable (and writeable) for a human, especially one that's had experience with other XML formats.

There's also other benefits to using XML, such as the wealth of tools available for processing it. The Mechapoint file format is quite low-level, describing in intimate detail what everything looks like, and while it can be read and written by humans, it's not really designed to be human-friendly. However, because it's XML, there's processing tools out there than can simplify generation of the Mechapoint file for the end user.

4.2.1. XSLT

XSL, or the Extensible Stylesheet Language, is an XML-based markup for writing stylesheets. XSL Transforms, or XSLT, uses XSL stylesheets to transfrom XML documents. Typically this is used to convert one format of XML into another. For instance, an XML document describing some data could be transformed using an XSL stylesheet into a HTML representation of the original data.

Here we have a brief description of a movie in a simple XML format:

An XSL stylesheet can be used to convert our XML-format movie description into an HTML rendering of it. XSL stylesheets are based on rules, which describe how to transform fragments of the document. Each rule is defined using an >xml:template<, which has a "match" attribute describing what part (or parts) of the document it matches. It's probably easiest to just look at the example:

When the stylesheet is applied to the original XML file using XSLT, the following HTML is generated:

This is just a simple example, and shows only a fraction of full power of XSL and XSL Transforms - there's stylesheet syntax for things such as logic and looping for instance - but for more complex applications the tag-based syntax can become limiting or annoying. I've implemented a very simple high-level syntax for Mechapoint, which is converted into Mechapoint format using an XSL stylesheet, but it's quite limiting, and won't be capable of doing some of the things I want to do. Because of this, I'm now investigating the use of custom Python code to parse a simple syntax and output Mechapoint files.