4. Message location
OCL-queries are executed whenever OCL-statement returns false, i.e. when error message needs to be displayed in the validation report. Their purpose is to locate a defined position of the XML-file, so that error message is shown in wherever the creator of the rule sees fit.
OCL-queries are optional. Whenever a query is not defined and OCL-statement returns false, the defined error message is shown in the location of context.
The usage of queries in XMLdation environment is often simple; they could be thought as an address where to point the error message, and often it is enough to list the desired element in an xPath style, but replacing context with "self" and separating elements using a dot notation.
Below example is used in the OCL-statement section of this wiki.
Rule defines a specific value for Debtor/Name when Debtor / Name is given.
|OCL-statement||self.Debtor.Name->size() = 1 implies self.Debtor.Name = "The initiator"|
|Message||Debtor / Name is not The initiator|
Here OCL-query is defiend to be self.Debtor.Name. This means that the error message is shown in that location, under Debtor / Name. Without the query defiend, error message would be shown on self, on element Header.
In this case, if the error message would be shown on header it most likely would not confuse the user, as the schema is small and it is fairly easy to locate the erroneous element and no other errors are present. In bigger shemas with multiple rules, however, queries help maping the validation report clear.