[rules-users] Solution for reasoning over XML?

craigparra craigparra at gmail.com
Sat Jan 12 00:10:56 EST 2013


Thanks guys,

In my case, we currently assert a known java object and a small set of
structured data (represented in XML) with it.  The structured data (XML)
isn't known at design-time, because it is user-configurable (the data
sources for document templates).   This excludes using jaxb or similar to
create java model objects, as the incoming schemas aren't known.  

But we would like the rule logic to be user configurable, using a natural
language DSL (hence drools).  We currently write and execute the logic in
groovy scripts, which are not very business friendly, are expensive for the
team to maintain, and will not scale out as our number of customers
increases.

Drools is a nice fit for that, but the question of how to efficiently reason
over XML is a sticking point.  Groovy has excellent XML support but drools
is a lacking.

As with Wolfgang's suggestion, I assert a wrapper object for each DOM
Element node; in our case, these number in the 10's per firing, so it's not
a massive amount of data.  From those elements I can reason over the DOM
tree using convenience methods.  It's probably expensive if conditionals
require traversal of the DOM tree (such as calculating the full path from
the root).

An alternative approach is to SAX parse the XML and build immutable objects
that are not backed by the DOM model.  This would process all possible
convenience values up front, even though they may not be used in conditions.

In our case, the structured data is read-only, so there is no need to call
modify or update (though this is technically possible I guess).  I haven't
implemented it.  

In my example

> An XML element exists 
> - named someName with a value of 
> - at path /some/xpathlike/someName with a value in
> "someVal","someOtherVal" 

Resolves to:

XmlElement ( name=="someName", path =="/some/xpathlike/someName" value in
("someVal","someOtherVal"))
 

So far the groovy executes about five times as fast as drools, but I think
that might be because I'm re-compiling the knowledge every time.  Not sure.



--
View this message in context: http://drools.46999.n3.nabble.com/Solution-for-reasoning-over-XML-tp4021454p4021478.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list