List types and union types

You can use list and union types in a schema and XML document.

This example demonstrates the use of list types 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.");
   }
}