Monday, 12 January 2009

Parameters, Variables and Context

CAM has a very subtle extra feature over its bigger challenger XML Schema.  This is the ability to change the rules that are applied at run-time, by using parameters.
These come in two forms global and local.  
global parameters are using to pass in a value that can be interpreted by conditional rules or contexts.  If for example a parameter existed called 'processing-style' that had a couple of options strict and lax, then a pair of context could be defined with the respective conditions of $processing-style = 'strict' and $processing-style = 'lax'.  Under each of these could be a set of rules that would be appropriate for the processing that is required.  By setting the value of the processing-style parameter at runtime the rules applied can be drastically changed without changing code.
local parameters are similar in that they are used to affect the rules that are applied, however, their values are derived from the contents of the xml file that is being processed.  This means that they have an xpath associated with them to derive a value.  local parameters can be re-evaluated by invoking the evaluateVariable action.  This cause the xpath of the parameter to be reparsed and a new value derived in the context of the node which contained the evaluateVariable action.  This can be useful when repeated sections of xml exist, but their contents are different.  For example the rules for for an order-line in a purchase-order could be different based on the item being ordered.  This could be achieved by evaluating the value of the parameter when a new order-line element is encountered.  
(evaluateVariable replaces the CAM specification scope attribute of a context node.)

In the future the ability to select the structure being processed will also be possible by simply choosing it using a parameter.  This would allow the run-time selection of the contents to be drastically changed, again without programming.

No comments:

Post a Comment