Page last modified 16:19, 8 Jan 2018 by Antero

B - Advanced 6 - Queries


    Purpose of this section is to introduce queries (message location) and how to give error/notice/info message in the location most useful to the person validating.


    Query can be though as a target on where we want the validation message to be displayed in a report. Query takes OCL as an input as well, which means we can have logic in the query. However, usually the format of a query is quite simple, an Xpath to the element but forward slashes replaced by dots

    In this section we will do the following to the rule made in section "advanced 5":

    1. Removing the query and testing
    2. Making an invalid query to see compilation error format
    3. Fixing the query
    4. Testing


    Logic of a query

    Before going to the instructions, logic of the query is good to be known. Following applies to queries:

    • Query is optional. If there is no query given, validation message will be given in context
    • If there is a query given and it can be found from the XML, message is given in the location where the query points
    • If there is a query given but its location is not found from the XML, message will be given in context
    • There may be multiple queries


    1: Removing the query and testing

    First, we should test the case of no query. Query can be removed by pressing the trash bin icon next to message location.

    We should see that no query and "self" as query has the same result. 

    2: Making an invalid query to see compilation error format

    Common erroneous case is to have a direct xpath as the message location query. We should test the following to see what the compilation error looks like:


    We should see the error message given if the query points to an invalid location, for example to


    and to



    3: Fixing the query

    Finally, we can add the correct query here. As we have a rule which makes Header/Debtor/Name mandatory, there are two different types of erroneous cases here:

    1. Debtor is not given
    2. Debtor is given, Debtor/Name is not given

    We can have a query for both of these cases by using following message location


    This means, that for the case when Debtor is not given, query is not found. Therefore, message location is given in context, in Header. This is the closes location where the message can be displayed, directly above the missing element in XML-tree

    For the case when Dbtr is given and Dbtr/Name is not, the query is found. Message location therefore will be in Debtor.

    For the case when Debtor is given and Debtor/Name is given as well, validation rule will return true and there is no need to return message. Given XML passes the validation rule.

    4: Testing

    We should test the above cases introduced in phase 3.

    We can also test to give the query to another element, for example to "self.TimeStamp". This would compile fine, but for validation usage clarity this wouldn't make much sense.