1
votes

I'm trying to read rules from XML using drools 6.3. I've tried to find some examples, but I found nothing of value, just one example of converting xml to drl which doesn't work because I'm using newer version of drools...

I converted drl example generated by eclipse to xml and replaced it by this xml. It looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<package name="com.sample" xmlns="http://drools.org/drools-5.2" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://drools.org/drools-5.2 drools.org/drools-5.2.xsd">
    <import name="com.sample.DroolsTest.Message"/>
    <rule name="Hello World">
        <lhs>
            <pattern identifier="m" object-type="Message">
                <expr>
                    status == Message.HELLO
                </expr>
                <expr>
                    myMessage : message
                </expr>
            </pattern>
        </lhs>
        <rhs>
            System.out.println( myMessage );
            m.setMessage( &quot;Goodbye cruel world&quot; );
            m.setStatus( Message.GOODBYE );
            update( m );
        </rhs>
    </rule>
    <rule name="GoodBye">
        <lhs>
            <pattern object-type="Message">
                <expr>
                    status == Message.GOODBYE
                </expr>
                <expr>
                    myMessage : message
                </expr>
            </pattern>
        </lhs>
        <rhs>
            System.out.println( myMessage );
        </rhs>
    </rule>
</package>

Right now drl is loaded like this:

KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules");

But this doesn't load xml files.

Is there any example how to load xml? Do I have to convert it to drl?

1

1 Answers

0
votes

The development of an XML version for DRL has been officially terminated several versions ago, around 5.2, IIRC. DRL has developed into a quite sophisticated language, and keeping its XML counterpart up-to-date has turned out to be a considerable but unrewarded effort.

Also, a conversion to the vendor-independent Rule-ML (for a subset of) DRL isn't something a vendor pursues eagerly, for obvious reasons.

It is not evident from your question why you are interested in rule authoring in XML. More help might be forthcoming if you add something of the background of your problem.