Test for the existence of a node

In some situations, you might use ambiguous paths to write shorter and more understandable expressions. You might need, for example, to check the length of an ID that is defined several times in a complex document. Such an expression could be:

if (length(\\id) <> 19)
{
   …
}

This works fine in most cases, but in some complex situations, addressing the ID node with an ambiguous path is not accurate enough. Imagine your input document contains both, customer IDs and supplier IDs, and that you need only to check customers’.

What you need is a way to discriminate customer IDs from supplier IDs. Most of the time the structure of the input is discriminative:

members
customer
id
name
address
.
.
.
phone
fax
discount_rate
supplier
id
name
address
.
.
.
phone
fax

These customer records include a discount_rate that is not present in supplier records. You can use the defined operator to check whether the id is one of your supplier or customer:

if (length(\\id[where defined item\..\discount_rate][1]) <> 19)
{
   …
}

The where clause matches only for ID nodes that do have a sibling node named discount_rate. When processing a defined operator statement, the integration engine checks whether the path that follows the operator leads to specified node. If so, the statement is evaluated to true, otherwise, the value is false.

In the previous example, statements enclosed between the curly brackets are evaluated only for customer IDs that are not 19 characters long.

You can reverse the condition using the undefined operator in the same conditions.

Related Links