[Tutor] xml question

Alan Gauld alan.gauld at btinternet.com
Tue Jul 27 01:38:11 CEST 2010


"Albert-Jan Roskam" <fomcl at yahoo.com> wrote

> The file should contain information about: ... (4) manual data edits 
> + datetime stamp + user name .
> I'd like to store this config file in xml.

Sounds sensible to me.

> ... 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?

I'm no expert on XML but that sounds like a fair approach.

> And should the manual edits be stored as an element 'edit' with 
> various
> attributes (the edit itself, the time stamp, etc.)?

My limited experience says to avoid relying on attributes and stick to 
separate subnodes.
Attributes are OK for very simple values that are always specified but 
anything
at all complex or optional should have its own (possibly optional) 
node.

As always, design from the outside in - make the XML reflect the data
strucures you will be using in the code and the parsing will be easier
and the XML more intuitive.

YMMV...

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/






More information about the Tutor mailing list