ILOG JRules User Guide > Integrating Application Data > Reference > Mapping Between XML Schema and Dynamic Classes > Schema Types > List and Union Types

This example demonstrates the use of list and union types in a schema and an XML document. The rules displayExtendedIntMeasure and displayStandardInt are used to test the MeasureSet objects.

Here is the schema:

<simpleType ExtendedInt>
  <union memberTypes="int string"/>
</simpleType>
<simpleType IntMeasures>
  <list itemType="ExtendedInt"/>
</simpleType>
<element name="measureSet" >
 <complexType>
  <sequence>
   <element name="intMeasures" type="IntMeasures" />
   <element name="extendedInt" type="ExtendedInt" />
  </sequence>
 </complexType>
</element>

Here is the excerpt from an XML document:

<measureSet>
  <intMeasures>1 2 3 4 ten 5 unknown</intMeasures>
  <extendedInt>3</extendedInt>
</measureSet>

Here is the XOM representation:

class MeasureSet extends IlrXmlObject
{
   Vector intMeasures; // list of (Integer| String) instances
   Object extendedInt; // either Integer or String instances
   ...
}

And here are the rules:

rule displayExtendedIntMeasure
{
   when {
     ms: MeasureSet ();
     m: String () in ms.intMeasures;
   }
   then {
     out.println ( m + " is an extended int.");
   }
}
rule displayStandardInt
{
   when {
     ms: MeasureSet ();
     m: Integer () from ms.extendedInt;
   }
   then {
     out.println ( m + " is a standard int.");
   }
}

Related Reference

Built-in Simple Types
Simple Type Mapping
Simple Types Derived from Other Simple Types
Local Simple Types Mapped onto Inner Classes
Complex Types
Extension of Simple Type Content in Complex Types
Complex Type Restriction
Complex Type Extension
Local Complex Types Mapped to Inner Classes
Default Constructor Dynamic Methods
Type Identifier Mapping