An XML schema just fitting your XML data will frequently not result in a class<br>hierarchy that&#39;s well suited for writing rules.<br><br>One point deals with representing the parent-child relationship, especially<br>when there are multiple children of a kind, i.e., the parent class contains a<br>
List&lt;?&gt;. You have this in XML the natural way; you lose it when you just<br>insert parents and children.  If extending the XML schema is possible, you<br>can add another element with minOccurs=&quot;0&quot; to the Child complexType of<br>
type Parent and set the reference to the current parent when you walk the<br>object tree. (You can erase the List&lt;?&gt; in the parent.) This avoids the<br>frequent use of the &quot;from&quot; clause in conditions.<br><br>
You may also have to handle repeated occurrences of elements that are<br>&quot;equal&quot; as objects but appear in full XML text; this is usually simple to handle<br>with a temporary Set, but you&#39;ll have to add hashCode and equals to the<br>
JAXB generated classes using the code injection plugin.<br><br>Inserting just the root element is not advisable, as you are well aware of.<br><br>-W<br><br><br><br><div class="gmail_quote">On 28 November 2010 12:38, Chris Selwyn <span dir="ltr">&lt;<a href="mailto:chris@selwyn-family.me.uk">chris@selwyn-family.me.uk</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I am working on a project that is using Drools to perform validation of<br>
hierarchical XML messages.<br>
<br>
So I have passed the XSDs through JAXB and have a set of interrelated<br>
Java objects.<br>
One of these objects (naturally) represents the root of the messages and<br>
the others represent the intermediate and leaf nodes of the message.<br>
<br>
My question is: Should I traverse the tree and insert each object into<br>
the working memory or should I just insert the root object into the<br>
working memory?<br>
<br>
If I insert each object into the memory then I have a lot of flexibility<br>
about how I write my rules... I can start by focussing on the particular<br>
part of the message that I want to detect an error in.<br>
However, I then have to perform a whole bunch of &quot;joining&quot; clauses to<br>
correctly &quot;connect up&quot; to the other objects in the working memory.<br>
(This is how I am doing it at the moment... I have a mechanism that uses<br>
the Java Introspector. It identifies by package name which parts of the<br>
data model get inserted into the WM)<br>
<br>
On the other hand, I could just insert the root object into the WM. This<br>
means that I would have to write really complicated where clauses on the<br>
root object but very much simplifies the WM loading process.<br>
<br>
All of the examples that I have seen have a very simple flat<br>
(non-hierarchical) structure that don&#39;t really give a hint as to what a<br>
&quot;best practice&quot; might be.<br>
<br>
Any suggestions/insights welcome :-)<br>
<font color="#888888"><br>
Chris Selwyn<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>