ILOG JRules User Guide > Integrating Application Data > Tasks > Using the XML Binding API > Configuring XML Binding > Inspecting an XML Model

Reflection information about the generated dynamic XML classes is accessible through metatype instances named IlrXmlClass and IlrXmlSimpleType. The package ilog.rules.xml.model provides schema model information at runtime through an API.

You can obtain the process reflection information for both simple types and complex types.

The following example shows how to obtain reflection information on an initialized data driver.

To obtain reflection information on a data driver:

import ilog.rules.xml.model.*;
IlrXmlDataDriver driver = ... // an initialized driver
IlrXmlModel reflect = driver.getXmlModel();
// obtaining class information
IlrXmlClass xmlClass = reflect.getClass ( "myClass" );
// obtaining simple type information
IlrXmlSimpleType xmlSimpleType = reflect.getSimpleType ( "mySimpleType" );

The following example shows how to obtain reflection information on a schema:

To obtain reflection information on a schema:

IlrContext context = ... //an initialized context
IlrXmlDataDriver  driver = ... //an initialized driver
IlrXmlModel xmlModel = driver.getXmlModel();
 
//get information on simple types: facets
IlrXmlSimpleType sType = xmlModel.getSimpleType ( "myType" );
IlrXmlConstraints ctrs = sType.getLocalConstraints ();
 
//get XML information on complex types
IlrXmlClass cType = xmlModel.getClass ( "myClass" );
int minoccurs = cType.getAttributeMinOccurs ( "attr1" );
Here is the schema:
<?xml version="1.0"?>
 
<schema targetNamespace="http://www.ilog.com/jrules/training/truck">
  <element name = "TruckModel">
     <complexType>
        <sequence>
           <element name="name" type="string"/>
           <element name="licenseClass" type="string"/>
           <element name="capacity" type="float"/>
           <element name="thresholdFull" type="float"/>
        </sequence>
     </complexType>
  </element>
</schema>
And here is the rule:
rule Threshold
{
   when {
   ?tm: TruckModel(capacity > 8000);
   }
   then {
      modify ?tm {thresholdFull = 0.9;}
   }
}

The following example includes a schema and two rules displayZipCodePattern and displayInvalidIntervalFloat to show how to process reflection information on simple types.

To process reflection information on a user simple type:

<simpleType name="zip-code">
  <restriction base="string">
    <pattern value="[0-9]{5}" />
  </restriction>
</simpleType>
<simpleType name="interval">
  <restriction base="float">
    <minInclusive value="10"/>
    <maxInclusive value="20"/>
  </restriction>
</simpleType>
And here are the rules:
rule displayZipCodePattern
{
   when {
       m: IlrXmlModel ();
       s: IlrXmlSimpleType() from m.getSimpleType ( null, "zip-code" );
   }
   then {
     out.printn ( "zip-code pattern : " + s.getPattern() );
   }
}
rule displayInvalidIntervalFloat
{
  when {
     m: IlrXmlModel ();
     s: IlrXmlSimpleType() from m.getSimpleType ( "Interval" );
     f: Float ( !s.isInstance ( this ) );
  }
  then {
     out.println ( "Invalid float " + f );
  }
}

The following example includes a schema and two rules displayCollectionAttribute and displayIntXmlElement to show how to process reflection information on complex types.

To process reflection information on a user complex type:

<complexType name="person"/>
  <sequence>
    <element name="name"/>
    <element name="surname" maxOccurs="4"/>
    <element name="age" type="int"/>
  </sequence>
</complexType>
And here are the rules:
rule displayCollectionAttribute
{
   when {
       m: IlrXmlModel ();
       c: IlrXmlClass() from m.getClass ( "Person" );
         attr: String ( c.isUnaryAttribute(this) ) in c.getAttributes();
   }
   then {
     out.println ( "collection attribute : " + attr );
   }
}
rule displayIntXmlElement
{
   when {
       m: IlrXmlModel ();
       c: IlrXmlClass() from m.getClass ( "Person" );
       attr: String (  ) in c.getAttributes();
       IlrXmlType ( getXmlName() equals "int" ) 
                    from c.getAttributeComponentType ( attr );
   }
   then {
     out.println ( "int element : " + c.getAttributeXmlName ( attr ) );
   }
}

Related Concepts

XML Binding
Web Service Binding

Related Tasks

Getting XPath Information on an IlrXmlObject