I’m currently working on an application which allows the user to read and a configuration for a device. The configuration is stored as XML.
The issue I’m faced with is how to define validation for the application. For example, most of the values I’m storing in the XML file have to be within different ranges, e.g. 0 – 2, 1 – 50, 10 characters or 20 characters, etc.
There are a lot of these constraints that I have to validate against, and I don’t want to hard-code the ranges because when version 2 of the device comes out the configuration file will have different set of ranges. E.g. instead of 0 – 2, it will be 0 – 4 and instead of 20 characters, 40 is now allowed.
How should I approach this? Should I store the validation rules in separate XML files? Should I define a class with hard-coded configuration ranges for this device, and create a new class for the version 2 of the device with its configuration ranges?
It could be done inside a
XML, so kind of declarative programming, where inXMLyou define a behaviour. But it’s not flexible and you easily can jump into pretty conplicated scenarious.What I personally would prefer to do is maintain the logic inside the code, but the parameters range that the data in source XML has to be checked against store in some
MatchData.xml.Hope this helps.