|
Re: Proposal: XML-- (read: XML minus minus)
|
Posted: Nov 11, 2005 5:46 AM
|
|
Funny you should mention configuration files.
When using XML for config, I've been doing something close to what you propose. In languages with reflection (C#, Java) this works quite well. When you encounter something like:
<something>somevalue</something>
this means that in the current context, we go look for an attribute "somevalue". Once found, we see if it's a property, field or function. In this case, we'd either call the function with 'somevalue' as parameter or set the field or property to 'somevalue'. How to pass somevalue (as string or something else) is done by requesting the type information, and asking the type information for a converter from string to appropriate type (e.g. Color, Integer, ...). This severely limits the allowed XML, approximately to what you propose. When needed, you can always extend the parser with more complex syntax (for example, i did something for accessing arrays and other indexed properties).
By nesting, you can "change context", e.g.: <myobject><something>somevalue</something><someother >12</someother></myobject> would set two properties in the object myobject. This behaviour is triggered by the content being more XML.
This worked very well in C#, but when I tried something like that in Python, I bumped into the fact that Python is equipped with excellent reflection, but objects don't have static types so you cannot decide whether you should set the someother property to a string or an integer.
In Python I took th Pythonic solution for configuration: Write config files in Python. Any one will understand and be able to modify a config file that says:
color="red" users = {"pete": "Peter Cambell", "claus": "Santa Claus"}
In fact, I find this syntax much more readable (and writable) than XML. XML may be ASCII printable, but it certainly is not human readable.
|
|