ILOG JRules User Guide > Integrating Application Data > Tasks > Using the XML Binding API > Managing Unknown Operators on Attributes and Elements

Unlike Java object attributes or elements, where isknown returns true even if the attribute or element is equal to null, XML objects can have optional attributes or elements that are unknown.

An optional XML attribute or element is unknown if, in the XML document:

In the ILOG Rule Language (IRL), you can check if there is a value for optional attributes using the isknown and isunknown operators and, if there is, retrieve it.

The operators isknown and isunknown do not exist in the Business Action Language (BAL). To apply these operators, you need to create a method in the BOM, then use BOM to XOM mapping. The following example shows an example for a lastName attribute.

To apply the isknown/isunknown operators:

  1. Create the following method in the BOM
  2. boolean isKnownLastName();
  3. In the BOM to XOM mapping, implement this method as:
  4. return isknown lastName;
  5. After verbalizing the isKnownLastName method, you can then protect access to the lastName attribute in the business rules. For example, you can write the following rule condition:
  6. If the last name of the customer is known and the last name of the customer is `Smith"
  7. Finally, if you need to change the attribute value to unknown: for non-primitive types, such as String, you need only set the attribute to null. In IRL code you can do this as:
  8. ?customer.lastName = null;

If the type of the optional attribute is a primitive type, the XML binding generates the XOM method setUnknown<AttributeName>. You can therefore unset an age attribute of type int using:

?customer.setUnknownAge();

Note
The unknown operator is often used to test a nullable field before de-referencing it. This avoids raising a null pointer exception (NPE) when tests are evaluated against the file in some rule conditions.

Related Concepts

XML Binding
The BOM to XOM Mapping Mechanism

Related Tasks

Adding XML Objects to the Working Memory
Using XML Objects as Ruleset Parameters
Assigning the Root Element Name of an XML Object
Reading an XML Document
Writing to an XML Document
Configuring XML Binding

Related Reference

Attributes

Tutorials and Samples

Tutorial: Creating Business Rules