I have the need to express simple conditionals as program input. The input must be human readable.
Is XML suited for this?
For example, I have the following conditional statement:
If AnimalType = Leopard And (SourceCountry = Kenya Or TargetCountry = Kenya) Then ZooKeeper=Jack Else ZooKeeper=Jill End If
Expressing the above in XML might look something like this:
<If> <Conditional> <And> <AnimalType>Leopard<AnimalType> <Or> <SourceCountry>Kenya</SourceCountry> <TargetCountry>Kenya</TargetCountry> </Or> </And> </Conditional> <True> <ZooKeeper>Jack</ZooKeeper> </True> <False> <ZooKeeper>Jill</ZooKeeper> <False> </If>
Any ideas on how best to represent conditional statements in XML?
I haven’t yet explored using attributes. I don’t currently have the need for nested ‘If’ statements or the ‘Else If’ clause, but I’m going to try and work them in anyway.
Perhaps the VB code is more ‘readable’ than XML can be in this case and I should create a custom flat-file format instead.
You said you wanted it to be human-readable, and then you presented a nearly impenetrable XML example. I’m not sure what XML is buying you here. A simple parser for a truly human-readable language would probably be a good investment of your time.