XML or YAML for configuration files

March 28th, 2006 at 6:34 pm

I’m planning to redesign and rewrite my ESMS project, and one of the most important issues a redesign of its configuration files.

Like virtually every project created by newbie programmers, ESMS is a museum of home-brewn configuration file formats. The three major configuration files the program uses are all different - one resembling INI files, another a curious attempt at templating (using printf-like format strings), and the third completely free style.

So, it’s time to something a bit more standartized. A standard file format (like XML) has three main benefits:

  1. It is far simpler to read into the program, without the need for custom-format-reading code.
  2. It is also simpler to generate, for the same reason as (1)
  3. Since it’s standard, at least some users are already familiar with it - and third party tools for editing / viewing exist

Until recently I was almost completely locked-in on XML, and even created a sample XML file for one of the configuration files. XML is a bit too verbose, however, so I decided to look into YAML as well.

YAML is gaining popularity in the domain of dynamic languages (Perl, Ruby, Python), for which it was originally intended. It is mainly suited to serve as a serialization format for data structures, but can be used for general-purpose data file tasks. Here are some useful links for YAML:

For my purposes, YAML seems to have one serious benefit over XML: it is cleaner. The syntax is far less cluttered and far less repetitive - lists of entries don’t have to repeat the entry name, for instance. XML, however, has benefits as well: first, it’s more familiar, and second, it can be verified very easily even by n00b users. It is a curious fact that although I’d assume YAML would be more compact space-wise, it actually isn’t because of the indentation significance and the ban of tabs.

The second reason in favor of XML is worth elaborating: my users mostly aren’t computer experts, they are just simple users who want to run a few fantasy football games with their friends. To use ESMS fully, one must edit the configuration files and fit it to his needs. While editing XML isn’t ideal in terms of simplicity, YAML is worse, IMHO. A user who’ve edited the XML file and wants to see that it’s well formed can just double click on it, firing up IE (or another web browser, but IE is usually default for .xml files) and see immediately if there are any syntactic mistakes. This can’t be done with YAML.

I still haven’t reached a conclusion on which format to choose, but I will :-)

Related posts:

  1. JSON is YAML, but YAML is not JSON
  2. Useful resources for using YAML in Ruby
  3. splitting MP3 files
  4. some thoughts on XML (XmlWriter and DOM)
  5. Accessible GUI development - call for ideas

2 Responses to “XML or YAML for configuration files”

  1. Anonymous Says:

    Would it make sense to use pudge’s or cwest’s scripts or something to duplicate your most perl-ish posts on use-perl? Having a single searchable comment web is a good ting.

    And I can’t in good conscience accept Blogger’s TOS.

    – Bill / n1vux

  2. eliben Says:

    I will do my best to cross-post the most Perlish posts to use.perl, although now with my new fascination with Ruby, I expect to have much less of those.

    What about the TOS (Terms of Service, I assume ?) of Blogger don’t you like ?
    I admit I haven’t even read it :)

Leave a Reply

To post code with preserved formatting, enclose it in `backticks` (even multiple lines)