[Tutor] xml question

Mac Ryan quasipedia at gmail.com
Tue Jul 27 11:46:58 CEST 2010

On Mon, 2010-07-26 at 12:09 -0700, Albert-Jan Roskam wrote:
> I am making a data processing program that will use a configuration
> file. The file should contain information about: (1) source files
> used, (2) (intermediate) output files, (3) used parameters/estimation
> methods (4) manual data edits + datetime stamp + user name . I'd like
> to store this config file in xml. However, I've never created
> something like this before. Is this a suitable format, and, if so,
> what would the elementtree look like? Should I just use 'config'  or
> something similar as root, and the information elements 1 through 3 as
> child elements? And should the manual edits be stored as an element
> 'edit' with various attributes (the edit itself, the time stamp,
> etc.)?

I am with Steven on the fact that XML might not necessarily be the best
choice, unless you plan to use the configuration file with other
third-party programs, in which case the fact that XML has built-in
parsing libs for nearly all languages makes life of fellow developer

For the next project of mines, I am planning to use YAML (YAML Ain't a
Markup Language). I stumbled upon this format while toying around with
the google app engine, that uses it for storing your application
configuration data. IMO, YAML has the following prominent advantages:
   1) It is easy to read and edit by humans [think "markdown"]
   2) It has solid parsing libraries for Python
   3) It is far less verbose than XML
   4) It is consistent with Python "relevant whitespaces" [indentation
is used to define data structure hierarchy]

I have not yet got to the stage of writing code that use YAML (will take
two more weeks at best for me to get to that point), but should you go
down this road, I would love to hear back from you. [As I would love to
hear from anybody else who might have experience with YAML+Python]

Some links:
- http://en.wikipedia.org/wiki/YAML [good overview of the format]
- http://www.yaml.org/ [official site... when consistency with the
format makes a website hard to browse!]
- http://pyyaml.org/wiki/PyYAMLDocumentation [documentation of the
library for Python - pure Python code // can use a C library]

An example of YAML file to give you the taste of it:
> receipt:     Oz-Ware Purchase Invoice
> date:        2007-08-06
> customer:
>     given:   Dorothy
>     family:  Gale
> items:
>     - part_no:   A4786
>       descrip:   Water Bucket (Filled)
>       price:     1.47
>       quantity:  4
>     - part_no:   E1628
>       descrip:   High Heeled "Ruby" Slippers
>       price:     100.27
>       quantity:  1
> bill-to:  &id001
>     street: |
>             123 Tornado Alley
>             Suite 16
>     city:   East Westville
>     state:  KS
> ship-to:  *id001
> specialDelivery:  >
>     Follow the Yellow Brick
>     Road to the Emerald City.
>     Pay no attention to the
>     man behind the curtain.


More information about the Tutor mailing list