Adding the root object of an XML data file
You can also add the root object of an XML data file.
To add the root object of an XML data file, use the following code:
IlrXmlObject obj = engine.loadXMLFile(xmlFileName);
engine.insert(obj);
By default, adding the root object does not do a recursive
add. Therefore, if you want to process rules on the other objects,
you must use the in and from keywords
in your rules to reach the objects that have not been added.
The function ilrmain is not called when you use Rule Execution Server. If you want to add objects or parameters to the working memory, add the code in the initial actions of the ruleflow to make sure that that code is called no matter how the ruleset is executed.
Example : a rule that uses the ‘in’ and ‘from’ keywords
Here is an extract from a rule named MatchSession1 to
illustrate the use of these keywords:
rule MatchSession1
{
when
{
?c: Conference();
?s: Session(?t: title.toLowerCase()) in ?c.sessionList;
?p: Participant() in ?c.participantList;
collect String(?t.indexOf(toLowerCase()) != -1) in ?p.interestList
where (size() >= 2);
}
...
Example : a rule that does not use the in and from keywords
Using an IlrXmlObjectAsserter object, you can add all the objects:
IlrXmlObjectAsserter asserter = new IlrXmlObjectAsserter(engine);
asserter.exploreObject (obj);
You can use an IlrXmlObjectAsserter object
to 'filter’ the added objects in the working memory. In this example,
all the objects have been added, hence there is no need to use the in or from keywords
in your rules.
Here is an extract from a rule that does not use these keywords:
rule processValidItem
{
priority=100;
when {
item: Item ( "waiting".equals(state) );
product: Product ( id.equals(item.product); stock >= item.quantity
);
}
...