Stage 1: XML schema processing

The XML schema processing converts schema types to XOM dynamic classes.

At compile time, the XML schema is processed by a schema driver (IlrXmlSchemaDriver). The schema driver converts the schema to dynamic data structures to create a XOM. This process is necessary to present the XML data in a format that the rule engine can read. The XOM is represented by the Java™ class IlrReflect.

Diagram showing the process by which XML schemas generate a XOM

In some cases, schema components are mapped directly to existing classes. In particular, this is the case for types such as String, Date, Vector, and other common types. XSD complex types, however, are converted to dynamic user classes specific to the schema being used.

The following table shows the XSD-to-XOM mapping that takes place when XML schemas are processed.

For more information on mapping, see Mapping between XML schema and dynamic classes.

Table 1. XSD to XOM Mapping
XSD XOM
Complex type XOM dynamic class
Elements, attributes, content Typed fields
Complex inheritance (restriction, extension) Inheritance
Built-in simple type Predefined Java type (primitive, object)
Restricted simple type Predefined Java type
Facets XOM static information
Application information (appinfo) XOM property

The following example shows how an address element is converted to the dynamic class Address.

Conversion of a simple schema

Schema:

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://
www.ilog.fr/Schema/Examples/simpleSchema1">
   <element name="address">
      <complexType>
         <sequence>
         <element name="city" type="string"/>
         <element name="zipcode" type="integer"/>
         </sequence>
         <attribute name="id" type="ID"/>
      </complexType>
   </element>
</schema>

XML document:

<?xml version="1.0"?>
<address xmlns = "http://www.ilog.fr/Schema/Examples/simpleSchema1">
   <city>New York</city>
   <zipcode>11275</zipcode>
</address>

Any dynamic class that is created from a schema extends the IlrXmlObject class.

class Address extends IlrXmlObject
{
   String id;
   String city;
   int zipcode;
}

After the dynamic objects have been instantiated, a rule can be applied on address objects and any fields tested. This example tries to match an address in the Chicago city.

...
rule Address
...
      ?a : address(city equals "Chicago")
...

Conversion of a more complex schema

The following example extends the simple example above by adding a street element. Here is the schema element:

<element name="street" >
      <complexType>
         <sequence>
            <element name="number" type="int"/>
            <element name="name" type="string"/>
         </sequence>
      </complexType>
 </element>

With a reference to this element in the previous address element as <element ref="street"/>:

<element name="address" >
   <complexType>
      <sequence>
         <element ref="street"/>
         <element name="city" type="string"/>
         <element name="zipcode" type="integer"/>
      </sequence>
      <attribute name="id" type="ID"/>
   </complexType>
</element>

The XML document now contains a street number and name:

<street>
   <number>32</number>
   <name>Elma Street</name>
</street>

The conversion results contains a new class Street and the class Address contains a field called street of type Street:

class Street extends IlrXmlObject
{
   int number;
   String name;
}
class Address extends IlrXmlObject
{
   ...
   Street street;
}

There are more ways of defining elements in schemas than in Java. Therefore, several schema definitions might map to the same dynamic class structure. For example, the following two lines of code give the same result for the XML document (though not necessarily for the XOM):

<element name="street" type="street">
<complexType name="street">

In this example, to indicate that the definition of the XSD type street must be continued, the address element is converted to a dynamic class Address. The city and zipcode subelements become fields of this class as the id schema attribute.

To be converted correctly, names must be unique within a schema definition. If you use the same name for a type, group, attribute, and element in a schema, an error is raised, unless you use a redefine instruction.