Martyn,
Yes. I think that this is a viable approach. I think that you will
need to extend DOM or JDOM to make your rules a bit more readable. In
my case, I use org.w3c.dom as a personal preference, because I feel that
it has a more expressive set of methods. I won't get in a religious
debate about it, though...
In any case, whether you use DOM or JDOM or something else, I feel that
there is value in extending the classes that you use. You may also want
to look at org.apache.xpath.XPathAPI.
This method allows me to query the XML document with XPATH as follows:
oNode node = XPathAPI.selectSingleNode(myDomObject.root(),
"//clnt/qty");
Note the explicit reference to the search context (myDomObject.root()).
In some cases, I want to search only a subset of the document.
There is another method which returns all of the matching nodes:
NodeList nodelist = XPathAPI.selectNodeList(myDomObject.root(),
"//clnt");
Basically, I look at it from the standpoint that DOM, JDOM and XPathAPI
are starting points for working with XML if you want to really do some
powerful things you need to extend them.
By expanding your XML tools to give you the real power that you need you
will be able to simplify the semantics of your logic.
Hope this helps,
Dave
-----Original Message-----
From: Martyn Bedford [mailto:[EMAIL PROTECTED]
Sent: Monday, November 07, 2005 9:23 AM
To: [email protected]
Subject: RE: [drools-user] Applying rules to an xml document
Sorry forgot to attach this, my fumbling so far
<?xml version="1.0"?>
<rule-set name="TVE"
xmlns="http://drools.org/rules"
xmlns:java="http://drools.org/semantics/java"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/rules
rules.xsd
http://drools.org/semantics/java java.xsd">
<java:import>java.lang.Object</java:import>
<java:import>java.lang.String</java:import>
<java:import>org.jdom.Document</java:import>
<java:import>org.jdom.Element</java:import>
<java:functions>
public void helloWorld(String hello)
{
System.err.println(hello + " World");
}
public void goodbyeWorld(String goodbye)
{
System.out.println(goodbye + " Cruel World");
}
</java:functions>
<rule name="ISINLength">
<parameter identifier="trade">
<class>Document</class>
</parameter>
<java:condition>trade.getRootElement().getChild("order").getAttribute("I
SIN").getValue().length()>7</java:condition>
<java:consequence>
helloWorld("Hello");
</java:consequence>
</rule>
</rule-set>
-----Original Message-----
From: Hamu, Dave [mailto:[EMAIL PROTECTED]
Sent: 07 November 2005 16:09
To: [email protected]
Subject: RE: [drools-user] Applying rules to an xml document
Martyn,
Well, this e-mail in part answers my previous question, in part.
However, I think that a better picture of the trade object (even a mock
up) would be useful in discussing the requirement further.
I am fully in agreement with the modeling of objects as XML documents --
a practice that I have applied for about 6 years. Surprisingly, I have
had to battle with very knowledgeable software engineers regarding this
practice, because they find it too revolutionary, but I have held firm
and now my colleagues are getting the idea.
Looking at it from a high level, I think that you could use XPATH, or
perhaps some class that extends JDOM to compare facts in the TradeXML
against specific conditions. These tests would be CONDITIONS in your
rule set and you could take whatever actions you desire in the
CONSEQUENCE.
Ah, the joys of design!
- Dave
-----Original Message-----
From: Martyn Bedford [mailto:[EMAIL PROTECTED]
Sent: Monday, November 07, 2005 8:25 AM
To: [email protected]
Subject: RE: [drools-user] Applying rules to an xml document
Geoffrey
The aim is to create a set of rules that can be used to validate trade
documents at various stages of their life cycle.
Starting with creation in a web app, through processing in a BPM layer.
The trade is represented as a xml doc which is good as far as it goes,
i.e. giving us good structure, but there is a forest of little rules
that need to be applied to the trade doc. Both to individual elements
and across element, such a the total of quantity attributes in one set
of elements must equal the total of quantity attributes in an other set
of elements By using Drools, which we successfully use to manage a very
large number of simple but related objects to manage a large and complex
single object such as a large xml doc, I feel we gain a lot from using
the common technology.
The main advantage I see here is that we can define a library of rules
which we can use and combine to create a really powerful trade
validation tool.
Martyn
-----Original Message-----
From: Geoffrey Wiseman [mailto:[EMAIL PROTECTED]
Sent: 07 November 2005 15:10
To: [email protected]
Subject: Re: [drools-user] Applying rules to an xml document
On 11/7/05, Martyn Bedford <[EMAIL PROTECTED]>
wrote:
>
> I would like to achieve the following
>
> Assert a single xml document to working memory and fire a rule base
> against the doc, the rule base will consist of a number of rules that
govern
> the behaviour of different parts of the doc.
>
Interesting; I'm not entirely sure that I clearly understand what you're
doing and what value you're trying to get from the rule engine here,
which might somewhat help to pick an approach.
Can anyone give me some pointers on how I should assert the doc to
working
> memory, i.e. is it a good idea to assert a single fact or break the
xml
> doc down into a number of separate facts; and how I target individual
> elements of the doc, I would naturally lean towards using xpath to
address
> specific elements of the doc.
>
If you're looking to use something like XPath, then it seems as if
supplying the entire document would make sense. However, then I begin to
wonder if you're going to get a lot of value out of the rule engine that
you won't get out of Java and XPath already. You may, if you have a lot
of little rules to run on a large XML document, and/or need to change
them regularly, but ...
curious. Either way, I hope you report back on your experiences, this
use of Drools would be novel to me at least.
- Geoffrey
Martyn
>
>
<http://www.greenhatconsulting.com/><http://www.greenhatconsulting.com>
>
> *Martyn Bedford*
>
> *Head of Solutions Practice*
>
> *Green Hat*
> 107-111 Fleet Street
> London
> EC4A 2AB
>
> Tel: +44 20 7936 9303
> Fax: +44 (0) 20 7936 9243
> Mobile: 0777 585 2584
>
> *www.greenhatconsulting.com* <http://www.greenhatconsulting.com>
>
>
<http://www.greenhatconsulting.com/emailfooter/index.html><http://www.gr
eenhatconsulting.com/emailfooter/index.html><http://www.greenhatconsulti
ng.com/emailfooter/index.html><http://www.greenhatconsulting.com/emailfo
oter/index.html>
>
> Registered in England and Wales as company number 3395844 and having
its
> registered office at Lynton House, 7-12 Tavistock Square, London, WC1H
9LY.
> The information in this internet E-mail is confidential and is
intended
> solely for the addressee. Unless you are the named addressee (or
authorised
> to receive it for the addressee) you may not copy or use it, or
disclose it
> to anyone else. Any views or opinions presented are solely those of
the
> author and do not necessarily represent those of Green Hat Consulting
Ltd.
> If you are not the intended recipient please contact
> [EMAIL PROTECTED]
>
>
--
Geoffrey Wiseman