Alternatives to XML?
Frank Millman
frank at chagford.com
Wed Aug 24 10:58:54 EDT 2016
Hi all
I have mentioned in the past that I use XML for storing certain structures
'off-line', and I got a number of comments urging me to use JSON or YAML
instead.
In fact XML has been working very well for me, but I am looking into
alternatives simply because of the issue of using '>' and '<' in attributes.
I can convert them to '>' and '<', but that imposes a cost in terms of
readability.
Here is a simple example -
<case>
<compare src="_param.auto_party_id" op="is_not" tgt="$None">
<case>
<on_insert>
<auto_gen args="_param.auto_party_id"/>
</on_insert>
<not_exists>
<literal value="<new>"/>
</not_exists>
</case>
</compare>
</case>
This is equivalent to the following python code -
if _param.auto_party_id is not None:
if on_insert:
value = auto_gen(_param.auto_party_id)
elif not_exists:
value = '<new>'
The benefit of serialising it is partly to store it in a database and read
it in at runtime, and partly to allow non-trusted users to edit it without
raising security concerns.
I ran my XML through some online converters, but I am not happy with the
results.
Here is a JSON version -
{
"case": {
"compare": {
"-src": "_param.auto_party_id",
"-op": "is_not",
"-tgt": "$None",
"case": {
"on_insert": {
"auto_gen": { "-args": "_param.auto_party_id" }
},
"not_exists": {
"literal": { "-value": "<new>" }
}
}
}
}
}
I can see how it works, but it does not seem as readable to me. It is not so
obvious that 'compare' has three arguments which are evaluated, and if true
the nested block is executed.
Here is a YAML version -
case:
compare:
case:
on_insert:
auto_gen:
_args: "_param.auto_party_id"
not_exists:
literal:
_value: "<new>"
_src: "_param.auto_party_id"
_op: is_not
_tgt: "$None"
This seems even worse from a readability point of view. The arguments to
'compare' are a long way away from the block to be executed.
Can anyone offer an alternative which is closer to my original intention?
Thanks
Frank Millman
More information about the Python-list
mailing list